• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

graphql-dotnet/conventions: GraphQL Conventions Library for .NET

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

graphql-dotnet/conventions

开源软件地址(OpenSource Url):

https://github.com/graphql-dotnet/conventions

开源编程语言(OpenSource Language):

C# 100.0%

开源软件介绍(OpenSource Introduction):

GraphQL Conventions Library for .NET

Introduction

GraphQL .NET has been around for a while. This library is a complementary layer on top that allows you to automatically wrap your .NET classes into GraphQL schema definitions using existing property getters and methods as field resolvers.

In short, this project builds on top of the following components:

Disclaimer: I am providing code in this repository to you under an open source licence (MIT). Because this is my personal repository, the licence you receive to my code is from me and not my employer (Facebook).

Installation

Download and install the package from NuGet:

PS> Install-Package GraphQL.Conventions

This project targets .NET Standard 2.0.

Getting Started

Implement your query type:

[ImplementViewer(OperationType.Query)]
public class Query
{
    [Description("Retrieve book by its globally unique ID.")]
    public Task<Book> Book(UserContext context, Id id) =>
        context.Get<Book>(id);

    [Description("Retrieve author by his/her globally unique ID.")]
    public Task<Author> Author(UserContext context, Id id) =>
        context.Get<Author>(id);

    [Description("Search for books and authors.")]
    public Connection<SearchResult> Search(
        UserContext context,
        [Description("Title or last name.")] NonNull<string> forString,
        [Description("Only return search results after given cursor.")] Cursor? after,
        [Description("Return the first N results.")] int? first)
    {
        return context
            .Search(forString.Value)
            .Select(node => new SearchResult { Instance = node })
            .ToConnection(first ?? 5, after);
    }
}

Construct your schema and run your query:

using GraphQL.Conventions;

var engine = GraphQLEngine.New<Query>();
var result = await engine
    .NewExecutor()
    .WithUserContext(userContext)
    .WithDependencyInjector(dependencyInjector)
    .WithRequest(requestBody)
    .Execute();

Examples

More detailed examples can be found in the unit tests.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
vnovick/graphql-jwt-tutorial发布时间:2022-06-13
下一篇:
mghoneimy/php-graphql-client: A PHP library that simplifies the process of inter ...发布时间:2022-06-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap