在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):graphql-dotnet/conventions开源软件地址(OpenSource Url):https://github.com/graphql-dotnet/conventions开源编程语言(OpenSource Language):C# 100.0%开源软件介绍(OpenSource Introduction):GraphQL Conventions Library for .NETIntroductionGraphQL .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:
InstallationDownload and install the package from NuGet: PS> Install-Package GraphQL.Conventions This project targets .NET Standard 2.0. Getting StartedImplement 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(); ExamplesMore detailed examples can be found in the unit tests. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论