GraphQL 5.3.2

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

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

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.

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.

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. Become a sponsor.

Showing the top 20 packages that depend on GraphQL.

Packages Downloads
GraphQL.DataLoader
GraphQL DataLoader implementation
52
GraphQL.NewtonsoftJson
JSON.NET serializer for GraphQL.NET
51
GraphQL.DataLoader
GraphQL DataLoader implementation
50
GraphQL.NewtonsoftJson
JSON.NET serializer for GraphQL.NET
49
GraphQL.NewtonsoftJson
JSON.NET serializer for GraphQL.NET
48
GraphQL.DataLoader
GraphQL DataLoader implementation
48
GraphQL.DataLoader
GraphQL DataLoader implementation
47
GraphQL.NewtonsoftJson
JSON.NET serializer for GraphQL.NET
46
GraphQL.MicrosoftDI
Microsoft DI extensions for GraphQL.NET
46
GraphQL.SystemTextJson
System.Text.Json serializer for GraphQL.NET
46
GraphQL.Server.Transports.AspNetCore
HTTP middleware for graphql
46
GraphQL.DataLoader
GraphQL DataLoader implementation
46

Version Downloads Last updated
8.8.0 5 11/18/2025
8.7.0 17 10/25/2025
8.6.0 14 9/24/2025
8.5.0 38 4/15/2025
8.4.1 27 3/3/2025
8.4.0 33 2/25/2025
8.3.1 31 2/20/2025
8.3.0 32 1/22/2025
8.2.1 36 11/2/2024
8.2.0 31 10/29/2024
8.1.0 35 9/19/2024
8.0.2 40 8/27/2024
8.0.1 30 8/27/2024
8.0.0 31 8/23/2024
7.9.0 37 8/18/2024
7.8.0 39 3/9/2024
7.7.2 42 3/9/2024
7.7.1 41 3/9/2024
7.7.0 46 3/9/2024
7.6.1 47 3/9/2024
7.6.0 40 3/9/2024
7.5.0 38 3/9/2024
7.4.1 39 3/9/2024
7.4.0 39 3/9/2024
7.3.1 33 3/9/2024
7.3.0 45 3/9/2024
7.2.2 41 3/9/2024
7.2.1 38 3/9/2024
7.2.0 36 3/9/2024
7.1.1 39 3/9/2024
7.1.0 43 3/9/2024
7.0.2 39 3/9/2024
7.0.1 41 3/9/2024
7.0.0 37 3/9/2024
5.4.0 39 3/9/2024
5.3.3 47 3/9/2024
5.3.2 40 3/9/2024
5.3.1 44 3/9/2024
5.3.0 38 3/9/2024
5.2.0 42 3/9/2024
5.1.1 42 3/9/2024
5.1.0 43 3/9/2024
5.0.0 48 3/9/2024
4.8.0 42 3/9/2024
4.7.1 42 3/9/2024
4.7.0 40 3/9/2024
4.6.1 37 3/9/2024
4.6.0 42 3/9/2024
4.5.0 47 3/9/2024
4.4.0 38 3/9/2024
4.3.0 44 3/9/2024
4.2.0 42 3/9/2024
4.1.0 37 3/9/2024
4.0.2 36 3/9/2024
4.0.1 37 3/9/2024
4.0.0 43 3/9/2024
3.3.2 42 3/9/2024
3.3.1 36 3/9/2024
3.3.0 46 3/9/2024
3.2.0 38 3/9/2024
3.1.6 38 3/9/2024
3.1.5 47 3/9/2024
3.1.4 39 3/9/2024
3.1.3 49 4/12/2022
3.1.2 39 3/9/2024
3.1.1 41 3/9/2024
3.1.0 35 3/9/2024
3.0.0.2026 38 3/9/2024
3.0.0 43 3/9/2024
3.0.0-preview-1719 36 3/6/2024
3.0.0-preview-1648 36 3/6/2024
3.0.0-preview-1490 45 3/6/2024
3.0.0-preview-1354 44 3/6/2024
3.0.0-preview-1352 36 3/6/2024
3.0.0-preview-1271 43 3/6/2024
3.0.0-preview-1268 37 3/6/2024
3.0.0-preview-1264 44 3/6/2024
3.0.0-preview-1211 39 3/6/2024
3.0.0-preview-1194 36 3/6/2024
3.0.0-preview-1175 37 3/6/2024
3.0.0-preview-1141 38 3/6/2024
3.0.0-preview-1107 39 3/6/2024
2.4.0 40 3/9/2024
2.3.0 40 3/9/2024
2.2.0 41 3/9/2024
2.1.0 35 3/9/2024
2.0.0 38 3/9/2024
2.0.0-preview-997 45 3/6/2024
2.0.0-preview-1002 33 3/6/2024
2.0.0-alpha-978 39 3/9/2024
2.0.0-alpha-952 39 3/9/2024
2.0.0-alpha-951 44 3/9/2024
2.0.0-alpha-947 35 3/9/2024
2.0.0-alpha-938 36 3/9/2024
2.0.0-alpha-937 43 3/9/2024
2.0.0-alpha-931 39 3/9/2024
2.0.0-alpha-927 39 3/9/2024
2.0.0-alpha-923 41 3/9/2024
2.0.0-alpha-912 38 3/9/2024
2.0.0-alpha-899 42 3/9/2024
2.0.0-alpha-887 37 3/9/2024
2.0.0-alpha-870 39 3/9/2024
2.0.0-alpha-868 50 3/9/2024
2.0.0-alpha-863 39 3/9/2024
2.0.0-alpha-859 40 3/9/2024
2.0.0-alpha-851 38 3/9/2024
2.0.0-alpha-839 42 3/9/2024
2.0.0-alpha-820 38 3/9/2024
2.0.0-alpha-817 44 3/9/2024
2.0.0-alpha-811 44 3/9/2024
2.0.0-alpha-805 37 3/9/2024
2.0.0-alpha-802 50 3/9/2024
2.0.0-alpha-797 40 3/9/2024
2.0.0-alpha-793 36 3/9/2024
2.0.0-alpha-783 40 3/9/2024
0.17.3 39 3/9/2024
0.17.2 42 3/9/2024
0.17.1 36 3/9/2024
0.17.0 37 3/9/2024
0.16.1 49 3/9/2024
0.16.0 41 3/9/2024
0.16.0-alpha-697 36 3/9/2024
0.15.1.678 36 3/9/2024
0.15.0.671 36 3/9/2024
0.14.7.667 37 3/9/2024
0.14.6.657 37 3/9/2024
0.14.5.654 42 3/9/2024
0.14.4.649 40 3/9/2024
0.14.3.646 31 3/9/2024
0.14.1.638 35 3/9/2024
0.14.0.633 41 3/9/2024
0.13.1.601 43 3/9/2024
0.13.0.562 40 3/9/2024
0.12.3.556 43 3/9/2024
0.12.2-alpha-550 34 2/26/2024
0.12.1-alpha-545 36 3/9/2024
0.12.0-alpha-538 40 3/9/2024
0.12.0-alpha-536 39 3/9/2024
0.12.0-alpha-511 36 3/9/2024
0.11.0.493 38 3/9/2024
0.10.3.478 42 3/9/2024
0.10.2.436 39 3/9/2024
0.10.1.349 35 3/9/2024
0.10.0.325 41 3/9/2024
0.10.0.323 34 3/9/2024
0.9.3 42 3/9/2024
0.9.2 39 3/9/2024
0.9.1 44 3/9/2024
0.9.0 36 3/9/2024
0.8.2 39 3/9/2024
0.8.1 40 3/9/2024
0.8.0 41 3/9/2024
0.8.0-alpha 38 3/9/2024
0.7.1 36 3/9/2024
0.7.0 37 3/9/2024
0.6.6 40 3/9/2024
0.6.5 39 3/9/2024
0.6.4 39 3/9/2024
0.6.3 36 3/9/2024
0.6.2 37 3/9/2024
0.6.1 44 3/9/2024
0.6.0 39 3/9/2024
0.5.1 35 3/9/2024
0.5.0 41 3/9/2024
0.4.1 34 3/9/2024
0.4.0 42 3/9/2024
0.3.0 35 3/9/2024
0.2.0 35 3/9/2024
0.1.1 35 3/9/2024
0.1.0 38 3/9/2024