forked fromgraphql-dotnet/conventions
- Notifications
You must be signed in to change notification settings - Fork1
GraphQL Conventions Library for .NET
License
NotificationsYou must be signed in to change notification settings
embracesbs/conventions
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
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:
- TheGraphQL library written byJoe McBride (MIT licence)
- The GraphQLlexer/parser originally written byMarek Magdziak (MIT licence)
Download and install the package fromNuGet:
PS>Install-Package GraphQL.Conventions
The following targets are available:
- .NET Framework 4.5
- .NET Platform Standard 1.5
Implement your query type:
[ImplementViewer(OperationType.Query)]publicclassQuery{[Description("Retrieve book by its globally unique ID.")]publicTask<Book>Book(UserContextcontext,Idid)=>context.Get<Book>(id);[Description("Retrieve author by his/her globally unique ID.")]publicTask<Author>Author(UserContextcontext,Idid)=>context.Get<Author>(id);[Description("Search for books and authors.")]publicConnection<SearchResult>Search(UserContextcontext,[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){returncontext.Search(forString.Value).Select(node=>newSearchResult{Instance=node}).ToConnection(first??5,after);}}
Construct your schema and run your query:
usingGraphQL.Conventions;varengine=GraphQLEngine.New<Query>();varresult=awaitengine.NewExecutor().WithUserContext(userContext).WithDependencyInjector(dependencyInjector).WithRequest(requestBody).Execute();
More detailed examples can be found in theunit tests.
About
GraphQL Conventions Library for .NET
Resources
License
Stars
Watchers
Forks
Packages0
No packages published
Languages
- C#100.0%