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.
You can install the latest version via NuGet.
PM> Install-Package GraphQL
Or you can get the latest pre-release packages from the MyGet feed.
http://graphql-dotnet.github.io
https://github.com/graphql-dotnet/examples
- API Development in .NET with GraphQL - Glenn Block demonstrates how to use the GraphQL .NET framework to build a fully functional GraphQL endpoint.
Define your schema with a top level query object then execute that query.
Fully-featured examples can be found here.
var schema = Schema.For(@"
type Query {
hello: String
}
");
var root = new { Hello = "Hello World!" };
var json = schema.Execute(_ =>
{
_.Query = "{ hello }";
_.Root = root;
});
Console.WriteLine(json);
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 = schema.Execute(_ =>
{
_.Query = "{ droid { id name } }";
});
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 = schema.Execute(_ =>
{
_.Query = $"{{ droid(id: \"123\") {{ id name }} }}";
});
- Grammar and AST for the GraphQL language should be compatible with the June 2018 specification.
- Scalars
- Objects
- Lists of objects/interfaces
- Interfaces
- Unions
- Arguments
- Variables
- Fragments
- Directives
- Include
- Skip
- Custom
- Enumerations
- Input Objects
- Mutations
- Subscriptions
- Async execution
- 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
- __typename
- __type
- name
- kind
- description
- fields
- interfaces
- possibleTypes
- enumValues
- inputFields
- ofType
- __schema
- types
- queryType
- mutationType
- subscriptionType
- directives
yarn run setVersion 2.0.0
git commit/push
download nuget from AppVeyor
upload nuget package to github
publish nuget from MyGet
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: