GraphQL 5.3.2
See the version list below for details.
dotnet add package GraphQL --version 5.3.2
NuGet\Install-Package GraphQL -Version 5.3.2
<PackageReference Include="GraphQL" Version="5.3.2" />
paket add GraphQL --version 5.3.2
#r "nuget: GraphQL, 5.3.2"
// Install GraphQL as a Cake Addin #addin nuget:?package=GraphQL&version=5.3.2 // Install GraphQL as a Cake Tool #tool nuget:?package=GraphQL&version=5.3.2
GraphQL for .NET
This is an implementation of Facebook's GraphQL in .NET.
Now the specification is being developed by the GraphQL Foundation.
This project uses a lexer/parser originally written by Marek Magdziak and released with a MIT license. Thank you Marek!
Provides the following packages:
Package | Downloads | NuGet Latest |
---|---|---|
GraphQL | ||
GraphQL.SystemTextJson | ||
GraphQL.NewtonsoftJson | ||
GraphQL.MemoryCache | ||
GraphQL.DataLoader | ||
GraphQL.MicrosoftDI |
You can get all preview versions from GitHub Packages. Note that GitHub requires authentication to consume the feed. See here.
Documentation
- http://graphql-dotnet.github.io - documentation site that is built from the docs folder in the
master
branch. - https://graphql.org/learn - learn about GraphQL, how it works, and how to use it.
Debugging
All packages generated from this repository come with embedded pdb and support Source Link. If you are having difficulty understanding how the code works or have encountered an error, then it is just enough to enable Source Link in your IDE settings. Then you can debug GraphQL.NET source code as if it were part of your project.
Installation
1. GraphQL.NET engine
This is the main package, the heart of the repository in which you can find all the necessary classes for GraphQL request processing.
> dotnet add package GraphQL
2. Serialization
For serialized results, you'll need an IGraphQLSerializer
implementation.
We provide several serializers (or you can bring your own).
> dotnet add package GraphQL.SystemTextJson
> dotnet add package GraphQL.NewtonsoftJson
Note: You can use
GraphQL.NewtonsoftJson
with .NET Core 3+, just be aware it lacks async writing capabilities so writing to an ASP.NET Core 3.0HttpResponse.Body
will require you to setAllowSynchronousIO
totrue
as per this announcement; which isn't recommended.
3. Document Caching
For caching of parsed GraphQL documents you'll need an IDocumentCache
implementation.
We provide in-memory implementation on top of Microsoft.Extensions.Caching.Memory
package.
> dotnet add package GraphQL.MemoryCache
For more information see Document Caching.
4. DataLoader
DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.
> dotnet add package GraphQL.DataLoader
For more information see DataLoader.
Note: Prior to version 4, the contents of this package was part of the main GraphQL.NET package.
5. Subscriptions
DocumentExecuter
can handle subscriptions as well as queries and mutations.
For more information see Subscriptions.
6. Advanced Dependency Injection
Also we provide some extra classes for advanced dependency injection usage on top of
Microsoft.Extensions.DependencyInjection.Abstractions
package.
> dotnet add package GraphQL.MicrosoftDI
For more information see Thread safety with scoped services.
Examples
https://github.com/graphql-dotnet/examples
You can also try an example of GraphQL demo server inside this repo - GraphQL.Harness. It supports the popular IDEs for managing GraphQL requests and exploring GraphQL schema:
Training
- API Development in .NET with GraphQL - Glenn Block demonstrates how to use the GraphQL.NET framework to build a fully functional GraphQL endpoint.
- Building GraphQL APIs with ASP.NET Core by Roland Guijt
Upgrade Guides
You can see the changes in public APIs using fuget.org.
Basic Usage
Define your schema with a top level query object then execute that query.
Fully-featured examples can be found here.
Hello World
using System;
using System.Threading.Tasks;
using GraphQL;
using GraphQL.Types;
using GraphQL.SystemTextJson; // First add PackageReference to GraphQL.SystemTextJson
var schema = Schema.For(@"
type Query {
hello: String
}
");
var root = new { Hello = "Hello World!" };
var json = await schema.ExecuteAsync(_ =>
{
_.Query = "{ hello }";
_.Root = root;
});
Console.WriteLine(json);
Schema First Approach
This example uses the GraphQL schema language. See the documentation for more examples and information.
public class Droid
{
public string Id { get; set; }
public string Name { get; set; }
}
public class Query
{
[GraphQLMetadata("droid")]
public Droid GetDroid()
{
return new Droid { Id = "123", Name = "R2-D2" };
}
}
var schema = Schema.For(@"
type Droid {
id: ID
name: String
}
type Query {
droid: Droid
}
", _ => {
_.Types.Include<Query>();
});
var json = await schema.ExecuteAsync(_ =>
{
_.Query = "{ droid { id name } }";
});
Parameters
public class Droid
{
public string Id { get; set; }
public string Name { get; set; }
}
public class Query
{
private List<Droid> _droids = new List<Droid>
{
new Droid { Id = "123", Name = "R2-D2" }
};
[GraphQLMetadata("droid")]
public Droid GetDroid(string id)
{
return _droids.FirstOrDefault(x => x.Id == id);
}
}
var schema = Schema.For(@"
type Droid {
id: ID
name: String
}
type Query {
droid(id: ID): Droid
}
", _ => {
_.Types.Include<Query>();
});
var json = await schema.ExecuteAsync(_ =>
{
_.Query = $"{{ droid(id: \"123\") {{ id name }} }}";
});
Roadmap
Grammar / AST
- Grammar and AST for the GraphQL language should be compatible with the October 2021 specification.
Operation Execution
- Scalars
- Objects
- Lists of objects/interfaces
- Interfaces
- Unions
- Arguments
- Variables
- Fragments
- Directives
- Include
- Skip
- Custom
- Enumerations
- Input Objects
- Mutations
- Subscriptions
- Async execution
Validation
- Arguments of correct type
- Default values of correct type
- Fields on correct type
- Fragments on composite types
- Known argument names
- Known directives
- Known fragment names
- Known type names
- Lone anonymous operations
- No fragment cycles
- No undefined variables
- No unused fragments
- No unused variables
- Overlapping fields can be merged
- Possible fragment spreads
- Provide non-null arguments
- Scalar leafs
- Unique argument names
- Unique directives per location
- Unique fragment names
- Unique input field names
- Unique operation names
- Unique variable names
- Variables are input types
- Variables in allowed position
- Single root field
Schema Introspection
GraphQL.NET supports introspection schema from October 2021 spec with some additional experimental introspection extensions.
Publishing NuGet packages
The package publishing process is automated with GitHub Actions.
After your PR is merged into master
or develop
, preview packages are published to GitHub Packages.
Stable versions of packages are published to NuGet when a release is created.
Contributors
This project exists thanks to all the people who contribute. <a href="https://github.com/graphql-dotnet/graphql-dotnet/graphs/contributors"><img src="https://opencollective.com/graphql-net/contributors.svg?width=890&button=false" /></a>
PRs are welcome! Looking for something to work on? The list of open issues is a great place to start. You can help the project simply respond to some of the asked questions.
The default branch is master
. It is designed for non-breaking changes, that is to publish versions 5.x.x.
If you have a PR with some breaking changes, then please target it to the develop
branch that tracks changes for v6.0.0.
Backers
Thank you to all our backers! 🙏 Become a backer.
<a href="https://opencollective.com/graphql-net#backers" target="_blank"><img src="https://opencollective.com/graphql-net/backers.svg?width=890"></a>
Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. Become a sponsor.
<a href="https://opencollective.com/graphql-net/sponsor/0/website" target="_blank"><img src="https://opencollective.com/graphql-net/sponsor/0/avatar.svg"></a> <a href="https://opencollective.com/graphql-net/sponsor/1/website" target="_blank"><img src="https://opencollective.com/graphql-net/sponsor/1/avatar.svg"></a> <a href="https://opencollective.com/graphql-net/sponsor/2/website" target="_blank"><img src="https://opencollective.com/graphql-net/sponsor/2/avatar.svg"></a> <a href="https://opencollective.com/graphql-net/sponsor/3/website" target="_blank"><img src="https://opencollective.com/graphql-net/sponsor/3/avatar.svg"></a> <a href="https://opencollective.com/graphql-net/sponsor/4/website" target="_blank"><img src="https://opencollective.com/graphql-net/sponsor/4/avatar.svg"></a> <a href="https://opencollective.com/graphql-net/sponsor/5/website" target="_blank"><img src="https://opencollective.com/graphql-net/sponsor/5/avatar.svg"></a> <a href="https://opencollective.com/graphql-net/sponsor/6/website" target="_blank"><img src="https://opencollective.com/graphql-net/sponsor/6/avatar.svg"></a> <a href="https://opencollective.com/graphql-net/sponsor/7/website" target="_blank"><img src="https://opencollective.com/graphql-net/sponsor/7/avatar.svg"></a> <a href="https://opencollective.com/graphql-net/sponsor/8/website" target="_blank"><img src="https://opencollective.com/graphql-net/sponsor/8/avatar.svg"></a> <a href="https://opencollective.com/graphql-net/sponsor/9/website" target="_blank"><img src="https://opencollective.com/graphql-net/sponsor/9/avatar.svg"></a>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- GraphQL-Parser (>= 8.0.0)
- Microsoft.CSharp (>= 4.7.0)
- System.ComponentModel.Annotations (>= 4.7.0)
- System.Memory (>= 4.5.5)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
.NETStandard 2.1
- GraphQL-Parser (>= 8.0.0)
- Microsoft.CSharp (>= 4.7.0)
- System.ComponentModel.Annotations (>= 4.7.0)
- System.Runtime.CompilerServices.Unsafe (>= 4.5.3)
-
net6.0
- GraphQL-Parser (>= 8.0.0)
- Microsoft.CSharp (>= 4.7.0)
- System.ComponentModel.Annotations (>= 4.7.0)
NuGet packages (200)
Showing the top 5 NuGet packages that depend on GraphQL:
Package | Downloads |
---|---|
GraphQL.NewtonsoftJson
JSON.NET serializer for GraphQL.NET |
|
GraphQL.SystemTextJson
System.Text.Json serializer for GraphQL.NET |
|
GraphQL.DataLoader
GraphQL DataLoader implementation |
|
GraphQL.MicrosoftDI
Microsoft DI extensions for GraphQL.NET |
|
GraphQL.Server.Transports.Subscriptions.Abstractions
Package Description |
GitHub repositories (28)
Showing the top 5 popular GitHub repositories that depend on GraphQL:
Repository | Stars |
---|---|
ThreeMammals/Ocelot
.NET API Gateway
|
|
OrchardCMS/OrchardCore
Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
|
|
Squidex/squidex
Headless CMS and Content Managment Hub
|
|
graphql-dotnet/graphql-client
A GraphQL Client for .NET Standard
|
|
JacekKosciesza/StarWars
GraphQL 'Star Wars' example using GraphQL for .NET, ASP.NET Core, Entity Framework Core
|
Version | Downloads | Last updated |
---|---|---|
8.2.1 | 95,017 | 10/24/2024 |
8.2.0 | 32,360 | 10/20/2024 |
8.1.0 | 57,512 | 9/18/2024 |
8.0.2 | 59,348 | 8/26/2024 |
8.0.1 | 5,671 | 8/23/2024 |
8.0.0 | 16,895 | 8/20/2024 |
7.9.0 | 88,420 | 8/18/2024 |
7.8.0 | 910,476 | 2/6/2024 |
7.7.2 | 192,245 | 12/16/2023 |
7.7.1 | 11,548 | 12/13/2023 |
7.7.0 | 1,461 | 12/13/2023 |
7.6.1 | 430,302 | 8/11/2023 |
7.6.0 | 270,806 | 7/31/2023 |
7.5.0 | 6,597,161 | 6/17/2023 |
7.4.1 | 281,764 | 4/21/2023 |
7.4.0 | 125,112 | 4/14/2023 |
7.3.1 | 353,323 | 4/2/2023 |
7.3.0 | 273,142 | 2/27/2023 |
7.2.2 | 302,053 | 1/2/2023 |
7.2.1 | 98,880 | 12/8/2022 |
7.2.0 | 106,940 | 12/3/2022 |
7.1.1 | 548,113 | 9/19/2022 |
7.1.0 | 6,611 | 9/16/2022 |
7.0.2 | 323,997 | 8/23/2022 |
7.0.1 | 32,775 | 8/17/2022 |
7.0.0 | 167,513 | 8/16/2022 |
5.4.0 | 289,101 | 11/30/2022 |
5.3.3 | 933,878 | 7/19/2022 |
5.3.2 | 229,346 | 7/3/2022 |
5.3.1 | 21,106 | 6/26/2022 |
5.3.0 | 1,498,884 | 5/14/2022 |
5.2.0 | 372,109 | 5/6/2022 |
5.1.1 | 511,390 | 4/11/2022 |
5.1.0 | 6,663 | 4/8/2022 |
5.0.0 | 69,652 | 3/30/2022 |
4.8.0 | 2,187,885 | 3/30/2022 |
4.7.1 | 1,222,989 | 1/1/2022 |
4.7.0 | 108,850 | 12/27/2021 |
4.6.1 | 1,327,441 | 9/29/2021 |
4.6.0 | 689,748 | 8/18/2021 |
4.5.0 | 980,806 | 4/29/2021 |
4.4.0 | 37,138 | 4/22/2021 |
4.3.0 | 276,444 | 4/16/2021 |
4.2.0 | 581,653 | 3/30/2021 |
4.1.0 | 723,499 | 3/26/2021 |
4.0.2 | 145,228 | 3/19/2021 |
4.0.1 | 4,624 | 3/17/2021 |
4.0.0 | 3,962 | 3/17/2021 |
3.3.2 | 1,300,743 | 1/24/2021 |
3.3.1 | 147,608 | 1/14/2021 |
3.3.0 | 6,471 | 1/14/2021 |
3.2.0 | 1,061,155 | 12/7/2020 |
3.1.6 | 444,181 | 12/1/2020 |
3.1.5 | 89,447 | 11/20/2020 |
3.1.4 | 47,207 | 11/15/2020 |
3.1.3 | 784,879 | 10/30/2020 |
3.1.2 | 86,761 | 10/28/2020 |
3.1.1 | 4,591 | 10/27/2020 |
3.1.0 | 57,385 | 10/23/2020 |
3.0.0.2026 | 846,972 | 9/17/2020 |
3.0.0 | 345,103 | 9/2/2020 |
3.0.0-preview-1719 | 19,195 | 8/17/2020 |
3.0.0-preview-1648 | 125,016 | 5/5/2020 |
3.0.0-preview-1490 | 225,295 | 2/19/2020 |
3.0.0-preview-1354 | 1,723 | 2/19/2020 |
3.0.0-preview-1352 | 196,575 | 11/23/2019 |
3.0.0-preview-1271 | 37,435 | 10/4/2019 |
3.0.0-preview-1268 | 146,277 | 9/17/2019 |
3.0.0-preview-1264 | 1,216 | 9/16/2019 |
3.0.0-preview-1211 | 7,140 | 8/16/2019 |
3.0.0-preview-1194 | 13,086 | 8/2/2019 |
3.0.0-preview-1175 | 18,193 | 6/4/2019 |
3.0.0-preview-1141 | 8,982 | 3/18/2019 |
3.0.0-preview-1107 | 3,546 | 3/2/2019 |
2.4.0 | 7,012,927 | 11/15/2018 |
2.3.0 | 1,403,465 | 10/17/2018 |
2.2.0 | 8,354 | 10/17/2018 |
2.1.0 | 99,141 | 9/30/2018 |
2.0.0 | 487,151 | 8/11/2018 |
2.0.0-preview-997 | 2,721 | 8/10/2018 |
2.0.0-preview-1002 | 2,434 | 8/11/2018 |
2.0.0-alpha-978 | 11,479 | 8/1/2018 |
2.0.0-alpha-952 | 9,976 | 7/25/2018 |
2.0.0-alpha-951 | 5,088 | 7/24/2018 |
2.0.0-alpha-947 | 5,484 | 7/19/2018 |
2.0.0-alpha-938 | 23,234 | 7/1/2018 |
2.0.0-alpha-937 | 2,495 | 6/29/2018 |
2.0.0-alpha-931 | 3,671 | 6/25/2018 |
2.0.0-alpha-927 | 4,319 | 6/18/2018 |
2.0.0-alpha-923 | 6,538 | 6/13/2018 |
2.0.0-alpha-912 | 11,288 | 5/16/2018 |
2.0.0-alpha-899 | 5,664 | 5/2/2018 |
2.0.0-alpha-887 | 8,701 | 4/20/2018 |
2.0.0-alpha-870 | 22,596 | 3/27/2018 |
2.0.0-alpha-868 | 17,891 | 3/15/2018 |
2.0.0-alpha-863 | 4,397 | 3/3/2018 |
2.0.0-alpha-859 | 2,848 | 2/25/2018 |
2.0.0-alpha-851 | 4,076 | 2/12/2018 |
2.0.0-alpha-839 | 13,379 | 1/23/2018 |
2.0.0-alpha-820 | 32,528 | 12/15/2017 |
2.0.0-alpha-817 | 3,688 | 12/2/2017 |
2.0.0-alpha-811 | 3,219 | 11/18/2017 |
2.0.0-alpha-805 | 3,861 | 11/3/2017 |
2.0.0-alpha-802 | 19,438 | 9/27/2017 |
2.0.0-alpha-797 | 2,169 | 9/23/2017 |
2.0.0-alpha-793 | 2,114 | 9/22/2017 |
2.0.0-alpha-783 | 5,527 | 9/16/2017 |
0.17.3 | 198,315 | 9/5/2017 |
0.17.2 | 29,121 | 8/2/2017 |
0.17.1 | 12,539 | 7/13/2017 |
0.17.0 | 2,881 | 7/10/2017 |
0.16.1 | 3,008 | 7/7/2017 |
0.16.0 | 2,673 | 7/6/2017 |
0.16.0-alpha-697 | 2,783 | 4/29/2017 |
0.15.1.678 | 66,829 | 3/2/2017 |
0.15.0.671 | 3,050 | 2/25/2017 |
0.14.7.667 | 2,547 | 2/24/2017 |
0.14.6.657 | 24,570 | 1/26/2017 |
0.14.5.654 | 3,447 | 1/19/2017 |
0.14.4.649 | 3,153 | 1/13/2017 |
0.14.3.646 | 2,638 | 1/13/2017 |
0.14.1.638 | 3,201 | 12/23/2016 |
0.14.0.633 | 36,495 | 11/30/2016 |
0.13.1.601 | 6,311 | 11/16/2016 |
0.13.0.562 | 3,735 | 10/14/2016 |
0.12.3.556 | 2,944 | 10/7/2016 |
0.12.2-alpha-550 | 2,283 | 10/7/2016 |
0.12.1-alpha-545 | 2,285 | 10/6/2016 |
0.12.0-alpha-538 | 3,063 | 9/16/2016 |
0.12.0-alpha-536 | 2,956 | 9/16/2016 |
0.12.0-alpha-511 | 2,352 | 8/29/2016 |
0.11.0.493 | 3,981 | 8/27/2016 |
0.10.3.478 | 2,608 | 8/27/2016 |
0.10.2.436 | 2,945 | 8/20/2016 |
0.10.1.349 | 4,257 | 7/30/2016 |
0.10.0.325 | 2,738 | 7/22/2016 |
0.10.0.323 | 2,645 | 7/22/2016 |
0.9.3 | 2,736 | 6/23/2016 |
0.9.2 | 2,825 | 6/18/2016 |
0.9.1 | 2,976 | 6/13/2016 |
0.9.0 | 2,823 | 6/10/2016 |
0.8.2 | 2,753 | 6/10/2016 |
0.8.1 | 17,987 | 6/8/2016 |
0.8.0 | 8,738 | 6/7/2016 |
0.8.0-alpha | 2,243 | 6/3/2016 |
0.7.1 | 6,925 | 6/4/2016 |
0.7.0 | 2,456 | 6/3/2016 |
0.6.6 | 2,583 | 5/12/2016 |
0.6.5 | 3,116 | 4/22/2016 |
0.6.4 | 2,522 | 4/19/2016 |
0.6.3 | 10,955 | 4/6/2016 |
0.6.2 | 2,559 | 3/23/2016 |
0.6.1 | 2,835 | 3/22/2016 |
0.6.0 | 2,716 | 3/22/2016 |
0.5.1 | 2,979 | 3/4/2016 |
0.5.0 | 2,519 | 3/2/2016 |
0.4.1 | 2,709 | 12/22/2015 |
0.4.0 | 6,273 | 12/12/2015 |
0.3.0 | 2,859 | 8/26/2015 |
0.2.0 | 4,873 | 7/16/2015 |
0.1.1 | 2,997 | 7/12/2015 |
0.1.0 | 7,942 | 7/8/2015 |