by graphql-dotnet

graphql-dotnet / graphql-dotnet

GraphQL for .NET

4.4K Stars 725 Forks Last release: 5 days ago (3.1.0) MIT License 1.2K Commits 69 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

GraphQL for .NET

Build Status Join the chat at

NuGet Nuget MyGet Nuget

Activity Activity Activity


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!


WARNING: The latest stable version 2.4.0 has many known issues that have been fixed in 3.0.0-preview-XXXX versions. If errors occur, it is recommended that you first check the behavior on the latest available preview version before reporting a issue. Latest 3.0.0-preview-XXXX versions are backwards incompatible with latest stable 2.4.0 version. You can see the changes in public APIs using

You can install the latest stable version via NuGet. ```

dotnet add package GraphQL ```

For serialized results, you'll need an

implementation. We support several serializers (or you can bring your own):

| Package | Downloads | Nuget Latest | MyGet Latest | |---------|-----------|--------------|--------------| | GraphQL.SystemTextJson | Nuget | Nuget | MyGet | | GraphQL.NewtonsoftJson, formerly included in GraphQL | Nuget | Nuget | MyGet |

> dotnet add package GraphQL.SystemTextJson
> dotnet add package GraphQL.NewtonsoftJson

Note: You can use

with .NET Core 3+, just be aware it lacks async writing capabilities so writing to an ASP.NET Core 3.0
will require you to set
as per this announcement; which isn't recommended.

You can get the latest pre-release packages from the MyGet feed, where you may want to explicitly pull a certain version using

. ```

dotnet add package GraphQL.SystemTextJson -v 3.0.0-preview-1593 ```

MyGet feed is the primary source of packages where you can find all preview versions built from the

branch. Periodically (usually once every few months) the latest preview version is published to NuGet manually. This is due to fairly frequent changes. Publication of each preview version to NuGet would create only unnecessary noise.


Note: The current state of documentation corresponds to the state of the code in the master branch which is used now to publish the *preview** package versions.*


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: - Altair - Firecamp - GraphiQL - GraphQL Playground - Voyager


Upgrade Guides

Basic Usage

Define your schema with a top level query object then execute that query.

Fully-featured examples can be found here.

Hello World

var schema = Schema.For(@"
  type Query {
    hello: String

var root = new { Hello = "Hello World!" }; var json = await schema.ExecuteAsync(_ => { _.Query = "{ hello }"; _.Root = root; });


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(); });

var json = await schema.ExecuteAsync(_ => { _.Query = "{ droid { id name } }"; });


public class Droid
  public string Id { get; set; }
  public string Name { get; set; }

public class Query { private List _droids = new List { 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(); });

var json = await schema.ExecuteAsync(_ => { _.Query = $"{{ droid(id: "123") {{ id name }} }}"; });


Grammar / AST

Operation Execution

  • [x] Scalars
  • [x] Objects
  • [x] Lists of objects/interfaces
  • [x] Interfaces
  • [x] Unions
  • [x] Arguments
  • [x] Variables
  • [x] Fragments
  • [x] Directives
    • [x] Include
    • [x] Skip
    • [x] Custom
  • [x] Enumerations
  • [x] Input Objects
  • [x] Mutations
  • [x] Subscriptions
  • [x] Async execution


  • [x] Arguments of correct type
  • [x] Default values of correct type
  • [x] Fields on correct type
  • [x] Fragments on composite types
  • [x] Known argument names
  • [x] Known directives
  • [x] Known fragment names
  • [x] Known type names
  • [x] Lone anonymous operations
  • [x] No fragment cycles
  • [x] No undefined variables
  • [x] No unused fragments
  • [x] No unused variables
  • [x] Overlapping fields can be merged
  • [x] Possible fragment spreads
  • [x] Provide non-null arguments
  • [x] Scalar leafs
  • [x] Unique argument names
  • [x] Unique directives per location
  • [x] Unique fragment names
  • [x] Unique input field names
  • [x] Unique operation names
  • [x] Unique variable names
  • [x] Variables are input types
  • [x] Variables in allowed position
  • [x] Single root field

Schema Introspection

  • [x] __typename
  • [x] __type
    • [x] name
    • [x] kind
    • [x] description
    • [x] fields
    • [x] interfaces
    • [x] possibleTypes
    • [x] enumValues
    • [x] inputFields
    • [x] ofType
  • [x] __schema
    • [x] types
    • [x] queryType
    • [x] mutationType
    • [x] subscriptionType
    • [x] directives

Publishing Nugets

yarn run setVersion 2.0.0
git commit/push
download nuget from AppVeyor
upload nuget package to github
publish nuget from MyGet

Running on OSX with mono

To run this project on OSX with mono you will need to add some configuration. Make sure mono is installed and add the following to your bash configuration:

export FrameworkPathOverride=/Library/Frameworks/Mono.framework/Versions/4.6.2/lib/mono/4.5/

See the following for more details:

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.