Giter VIP home page Giter VIP logo

graphql-dotnet's Introduction

GraphQL for .NET

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

This is an implementation of Facebook's GraphQL in .NET.

This project uses a lexer/parser originally written by Marek Magdziak and released with a MIT license. Thank you Marek!

Installation

You can install the latest version via NuGet.

PM> Install-Package GraphQL

Documentation

http://graphql-dotnet.github.io

Examples

https://github.com/graphql-dotnet/examples

Training

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 = schema.Execute(_ =>
{
  _.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 = schema.Execute(_ =>
{
  _.Query = "{ hero { 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 = schema.Execute(_ =>
{
  _.Query = $"{{ hero(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 (help with this rule)
  • 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

Schema Introspection

  • __typename
  • __type
    • name
    • kind
    • description
    • fields
    • interfaces
    • possibleTypes
    • enumValues
    • inputFields
    • ofType
  • __schema
    • types
    • queryType
    • mutationType
    • subscriptionType
    • 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:

graphql-dotnet's People

Contributors

acronoah avatar alexmcmillan avatar cable729 avatar cdroulers avatar derwasp avatar gingermike avatar giorgi avatar glennblock avatar jaymitchell avatar joemcbride avatar johnrutherford avatar jquense avatar kamil-mrzyglod avatar kiril-chilingarashvili avatar koditkarvedant avatar mahald avatar mnie avatar moserware avatar mvestergaard avatar pascalsenn avatar pekkah avatar randyridge avatar rehansaeed avatar rmc00 avatar ruxo avatar scmccart avatar seralexeev avatar simoncropp avatar tlil avatar wingsking avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.