GraphQL 7.2.0

.NET 5.0 .NET Standard 2.0
dotnet add package GraphQL --version 7.2.0
NuGet\Install-Package GraphQL -Version 7.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GraphQL" Version="7.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GraphQL --version 7.2.0
#r "nuget: GraphQL, 7.2.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install GraphQL as a Cake Addin
#addin nuget:?package=GraphQL&version=7.2.0

// Install GraphQL as a Cake Tool
#tool nuget:?package=GraphQL&version=7.2.0

GraphQL for .NET

Join the chat at https://gitter.im/graphql-dotnet/graphql-dotnet

Test code Build artifacts Publish code CodeQL analysis codecov

Backers on Open Collective Sponsors on Open Collective

Activity Activity Activity

Size

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 Nuget Nuget
GraphQL.SystemTextJson Nuget Nuget
GraphQL.NewtonsoftJson Nuget Nuget
GraphQL.MemoryCache Nuget Nuget
GraphQL.DataLoader Nuget Nuget
GraphQL.MicrosoftDI Nuget Nuget

You can get all preview versions from GitHub Packages. Note that GitHub requires authentication to consume the feed. See here.

Documentation

  1. http://graphql-dotnet.github.io - documentation site that is built from the docs folder in the master branch.
  2. 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.0 HttpResponse.Body will require you to set AllowSynchronousIO to true as per this announcement; which isn't recommended.

3. Document Caching

The recommended way to setup caching layer (for caching of parsed GraphQL documents) is to inherit from IConfigureExecution interface and register your class as its 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

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

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 7.x.x. If you have a PR with some breaking changes, then please target it to the develop branch that tracks changes for v8.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
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (144)

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.Server.Transports.Subscriptions.Abstractions

Package Description

GraphQL.DataLoader

GraphQL DataLoader implementation

GraphQL.Authorization

A toolset for authorizing access to graph types for GraphQL.NET

GitHub repositories (24)

Showing the top 5 popular GitHub repositories that depend on GraphQL:

Repository Stars
ThreeMammals/Ocelot
.NET core 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
phongnguyend/Practical.CleanArchitecture
Asp.Net Core 6 Clean Architecture (Microservices + Dapr, Modular Monolith, Monolith), Blazor, Angular 14, React 18, Vue 2.7, Domain-Driven Design, CQRS, SOLID, Asp.Net Core Identity Custom Storage, Identity Server 4 Admin UI, Entity Framework Core, Selenium, SignalR, Hosted Services, Health Checks, Cloud (Azure, AWS) Services, ...
JacekKosciesza/StarWars
GraphQL 'Star Wars' example using GraphQL for .NET, ASP.NET Core, Entity Framework Core
Version Downloads Last updated
7.2.0 53 12/3/2022
7.1.1 50,314 9/19/2022
7.1.0 2,692 9/16/2022
7.0.2 48,507 8/23/2022
7.0.1 7,706 8/17/2022
7.0.0 11,612 8/16/2022
5.4.0 90 11/30/2022
5.3.3 147,954 7/19/2022
5.3.2 129,110 7/3/2022
5.3.1 8,130 6/26/2022
5.3.0 326,822 5/14/2022
5.2.0 22,340 5/6/2022
5.1.1 157,452 4/11/2022
5.1.0 3,472 4/8/2022
5.0.0 21,125 3/30/2022
4.8.0 181,194 3/30/2022
4.7.1 551,226 1/1/2022
4.7.0 71,447 12/27/2021
4.6.1 552,067 9/29/2021
4.6.0 378,439 8/18/2021
4.5.0 548,033 4/29/2021
4.4.0 24,619 4/22/2021
4.3.0 97,267 4/16/2021
4.2.0 213,305 3/30/2021
4.1.0 355,574 3/26/2021
4.0.2 77,068 3/19/2021
4.0.1 2,547 3/17/2021
4.0.0 1,527 3/17/2021
3.3.2 634,642 1/24/2021
3.3.1 42,877 1/14/2021
3.3.0 2,921 1/14/2021
3.2.0 503,898 12/7/2020
3.1.6 265,245 12/1/2020
3.1.5 37,034 11/20/2020
3.1.4 30,665 11/15/2020
3.1.3 344,224 10/30/2020
3.1.2 49,694 10/28/2020
3.1.1 2,441 10/27/2020
3.1.0 39,948 10/23/2020
3.0.0.2026 563,429 9/17/2020
3.0.0 240,025 9/2/2020
3.0.0-preview-1719 14,591 8/17/2020
3.0.0-preview-1648 62,888 5/5/2020
3.0.0-preview-1490 169,818 2/19/2020
3.0.0-preview-1354 1,085 2/19/2020
3.0.0-preview-1352 161,193 11/23/2019
3.0.0-preview-1271 29,876 10/4/2019
3.0.0-preview-1268 89,426 9/17/2019
3.0.0-preview-1264 675 9/16/2019
3.0.0-preview-1211 6,654 8/16/2019
3.0.0-preview-1194 12,348 8/2/2019
3.0.0-preview-1175 15,371 6/4/2019
3.0.0-preview-1141 8,238 3/18/2019
3.0.0-preview-1107 2,811 3/2/2019
2.4.0 4,747,218 11/15/2018
2.3.0 827,069 10/17/2018
2.2.0 6,549 10/17/2018
2.1.0 77,021 9/30/2018
2.0.0 365,066 8/11/2018
2.0.0-preview-997 2,183 8/10/2018
2.0.0-preview-1002 1,866 8/11/2018
2.0.0-alpha-978 10,284 8/1/2018
2.0.0-alpha-952 7,451 7/25/2018
2.0.0-alpha-951 4,157 7/24/2018
2.0.0-alpha-947 4,350 7/19/2018
2.0.0-alpha-938 21,367 7/1/2018
2.0.0-alpha-937 1,902 6/29/2018
2.0.0-alpha-931 3,099 6/25/2018
2.0.0-alpha-927 3,623 6/18/2018
2.0.0-alpha-923 5,927 6/13/2018
2.0.0-alpha-912 10,298 5/16/2018
2.0.0-alpha-899 5,002 5/2/2018
2.0.0-alpha-887 7,644 4/20/2018
2.0.0-alpha-870 18,100 3/27/2018
2.0.0-alpha-868 9,327 3/15/2018
2.0.0-alpha-863 3,793 3/3/2018
2.0.0-alpha-859 2,294 2/25/2018
2.0.0-alpha-851 3,394 2/12/2018
2.0.0-alpha-839 8,528 1/23/2018
2.0.0-alpha-820 15,006 12/15/2017
2.0.0-alpha-817 3,112 12/2/2017
2.0.0-alpha-811 2,566 11/18/2017
2.0.0-alpha-805 3,303 11/3/2017
2.0.0-alpha-802 17,764 9/27/2017
2.0.0-alpha-797 1,733 9/23/2017
2.0.0-alpha-793 1,580 9/22/2017
2.0.0-alpha-783 4,824 9/16/2017
0.17.3 166,551 9/5/2017
0.17.2 25,313 8/2/2017
0.17.1 11,595 7/13/2017
0.17.0 2,216 7/10/2017
0.16.1 2,386 7/7/2017
0.16.0 2,019 7/6/2017
0.16.0-alpha-697 2,225 4/29/2017
0.15.1.678 60,127 3/2/2017
0.15.0.671 2,409 2/25/2017
0.14.7.667 1,937 2/24/2017
0.14.6.657 18,733 1/26/2017
0.14.5.654 2,783 1/19/2017
0.14.4.649 2,537 1/13/2017
0.14.3.646 1,953 1/13/2017
0.14.1.638 2,515 12/23/2016
0.14.0.633 20,254 11/30/2016
0.13.1.601 5,295 11/16/2016
0.13.0.562 2,995 10/14/2016
0.12.3.556 2,190 10/7/2016
0.12.2-alpha-550 1,713 10/7/2016
0.12.1-alpha-545 1,746 10/6/2016
0.12.0-alpha-538 2,539 9/16/2016
0.12.0-alpha-536 2,389 9/16/2016
0.12.0-alpha-511 1,803 8/29/2016
0.11.0.493 3,273 8/27/2016
0.10.3.478 1,967 8/27/2016
0.10.2.436 2,311 8/20/2016
0.10.1.349 2,758 7/30/2016
0.10.0.325 2,047 7/22/2016
0.10.0.323 2,024 7/22/2016
0.9.3 2,077 6/23/2016
0.9.2 2,195 6/18/2016
0.9.1 2,372 6/13/2016
0.9.0 2,183 6/10/2016
0.8.2 2,109 6/10/2016
0.8.1 17,329 6/8/2016
0.8.0 8,070 6/7/2016
0.8.0-alpha 1,716 6/3/2016
0.7.1 6,092 6/4/2016
0.7.0 1,891 6/3/2016
0.6.6 1,972 5/12/2016
0.6.5 2,506 4/22/2016
0.6.4 1,900 4/19/2016
0.6.3 8,181 4/6/2016
0.6.2 1,945 3/23/2016
0.6.1 2,235 3/22/2016
0.6.0 2,132 3/22/2016
0.5.1 2,374 3/4/2016
0.5.0 1,892 3/2/2016
0.4.1 2,093 12/22/2015
0.4.0 4,662 12/12/2015
0.3.0 2,202 8/26/2015
0.2.0 2,718 7/16/2015
0.1.1 2,318 7/12/2015
0.1.0 3,701 7/8/2015