Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/graphql-dotnet/conventions
GraphQL Conventions Library for .NET
https://github.com/graphql-dotnet/conventions
api conventions dotnet dotnetcore graphql schema
Last synced: 3 days ago
JSON representation
GraphQL Conventions Library for .NET
- Host: GitHub
- URL: https://github.com/graphql-dotnet/conventions
- Owner: graphql-dotnet
- License: mit
- Created: 2016-01-08T23:56:46.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-08-24T13:54:08.000Z (4 months ago)
- Last Synced: 2024-12-02T02:03:56.488Z (10 days ago)
- Topics: api, conventions, dotnet, dotnetcore, graphql, schema
- Language: C#
- Homepage:
- Size: 3.51 MB
- Stars: 233
- Watchers: 21
- Forks: 63
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
- awesome-dotnet-core - graphql-convention - 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 (Frameworks, Libraries and Tools / API)
- fucking-awesome-dotnet-core - graphql-convention - 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 (Frameworks, Libraries and Tools / API)
- awesome-dotnet-core - graphql-convention - 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 (Frameworks, Libraries and Tools / API)
- awesome-dotnet-core - graphql-convention - 该库是GraphQL的补充层,使您可以使用现有的属性和方法作为字段解析器,将.NET类自动包装到GraphQL模式定义中。 (框架, 库和工具 / API)
README
GraphQL Conventions Library for .NET
====================================## Introduction
[GraphQL .NET](https://www.github.com/graphql-dotnet/graphql-dotnet) 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:
* The [GraphQL](https://github.com/graphql-dotnet/graphql-dotnet) library written by [Joe McBride](https://github.com/joemcbride) (MIT licence)
* The GraphQL [lexer/parser](http://github.com/graphql-dotnet/parser) originally written by [Marek Magdziak](https://github.com/mkmarek) (MIT licence)>**Disclaimer:**
>I am providing code in this repository to you under an open source licence ([MIT](LICENSE.md)). 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](https://www.nuget.org/packages/GraphQL.Conventions):
```powershell
PS> Install-Package GraphQL.Conventions
```This project targets [.NET Standard] 2.0.
[.NET Standard]: https://docs.microsoft.com/en-us/dotnet/standard/net-standard
## Getting Started
Implement your query type:
```cs
[ImplementViewer(OperationType.Query)]
public class Query
{
[Description("Retrieve book by its globally unique ID.")]
public Task Book(UserContext context, Id id) =>
context.Get(id);[Description("Retrieve author by his/her globally unique ID.")]
public Task Author(UserContext context, Id id) =>
context.Get(id);[Description("Search for books and authors.")]
public Connection Search(
UserContext context,
[Description("Title or last name.")] NonNull 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:
```cs
using GraphQL.Conventions;var engine = GraphQLEngine.New();
var result = await engine
.NewExecutor()
.WithUserContext(userContext)
.WithDependencyInjector(dependencyInjector)
.WithRequest(requestBody)
.Execute();
```## Examples
More detailed examples can be found in the [unit tests](https://github.com/graphql-dotnet/conventions/tree/master/test/GraphQL.Conventions.Tests).