All Projects → graphql-dotnet → Graphql Dotnet

graphql-dotnet / Graphql Dotnet

Licence: mit
GraphQL for .NET

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Graphql Dotnet

Graphql Apis
📜 A collective list of public GraphQL APIs
Stars: ✭ 3,525 (-29.93%)
Mutual labels:  api, graphql, graphiql
Templates
.NET project templates with batteries included, providing the minimum amount of code required to get you going faster.
Stars: ✭ 2,864 (-43.07%)
Mutual labels:  api, graphql, dotnet-core
Hotchocolate
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
Stars: ✭ 3,009 (-40.19%)
Mutual labels:  graphql, dotnet-core, graphql-dotnet
Figma Graphql
The reimagined Figma API (super)powered by GraphQL
Stars: ✭ 354 (-92.96%)
Mutual labels:  api, graphql
Graphql Core
A Python 3.6+ port of the GraphQL.js reference implementation of GraphQL.
Stars: ✭ 344 (-93.16%)
Mutual labels:  api, graphql
Askql
AskQL is a query language that can express any data request
Stars: ✭ 352 (-93%)
Mutual labels:  api, graphql
Villus
🏎 A tiny and fast GraphQL client for Vue.js
Stars: ✭ 378 (-92.49%)
Mutual labels:  api, graphql
Wp Graphql Acf
WPGraphQL for Advanced Custom Fields
Stars: ✭ 358 (-92.88%)
Mutual labels:  api, graphql
Django Restql
Turn your API made with Django REST Framework(DRF) into a GraphQL like API.
Stars: ✭ 396 (-92.13%)
Mutual labels:  api, graphql
Graphql Php
A PHP port of GraphQL reference implementation
Stars: ✭ 4,219 (-16.14%)
Mutual labels:  api, graphql
Typegql
Create GraphQL schema with TypeScript classes.
Stars: ✭ 415 (-91.75%)
Mutual labels:  api, graphql
Grand Stack Starter
Simple starter project for GRANDstack full stack apps
Stars: ✭ 419 (-91.67%)
Mutual labels:  api, graphql
Wp Graphql Woocommerce
Add WooCommerce support and functionality to your WPGraphQL server
Stars: ✭ 318 (-93.68%)
Mutual labels:  api, graphql
Altair
✨⚡️ A beautiful feature-rich GraphQL Client for all platforms.
Stars: ✭ 3,827 (-23.93%)
Mutual labels:  graphql, graphiql
Absinthe
The GraphQL toolkit for Elixir
Stars: ✭ 3,805 (-24.37%)
Mutual labels:  api, graphql
Graphql Starter
💥 Monorepo template (seed project) pre-configured with GraphQL API, PostgreSQL, React, Relay, and Material UI.
Stars: ✭ 3,377 (-32.88%)
Mutual labels:  api, graphql
Django Api Domains
A pragmatic styleguide for Django API Projects
Stars: ✭ 365 (-92.74%)
Mutual labels:  api, graphql
V8 Archive
Directus Database API — Wraps Custom SQL Databases with a REST/GraphQL API
Stars: ✭ 486 (-90.34%)
Mutual labels:  api, graphql
Express Graphql Mongodb Boilerplate
A boilerplate for Node.js apps / GraphQL-API / Authentication from scratch - express, graphql - (graphql compose), mongodb (mongoose).
Stars: ✭ 288 (-94.28%)
Mutual labels:  api, graphql
Vulcain
Fast and idiomatic client-driven REST APIs.
Stars: ✭ 3,190 (-36.59%)
Mutual labels:  api, graphql

GraphQL for .NET

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

Test code Build artifacts Publish code CodeQL analysis

codecov Total alerts Language grade: C#

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.SystemReactive 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 IDocumentWriter 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

For handling subscriptions you'll need an instance of DocumentExecuter that supports this GraphQL operation type. DocumentExecuter class from the main GraphQL.NET package supports only queries and mutations. We provide SubscriptionDocumentExecuter implementation on top of System.Reactive packages.

> dotnet add package GraphQL.SystemReactive

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

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

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

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 4.x.x. If you have a PR with some breaking changes, then please target it to the develop branch.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].