Skip to content

Instantly share code, notes, and snippets.

@koistya
Last active June 9, 2017 17:59
Show Gist options
  • Save koistya/aff5ef003d5e137a165c26bba2b224f7 to your computer and use it in GitHub Desktop.
Save koistya/aff5ef003d5e137a165c26bba2b224f7 to your computer and use it in GitHub Desktop.
GraphQL with .NET Core, C#
namespace Example
{
public class RootQueryType
{
public Func<string> Hello { get; set; } = () => "world";
}
public class Schema
{
public RootQueryType Query { get; set; }
}
}
namespace Example
{
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.UseGraphQL<Schema>();
}
public static void Main()
{
var host = new WebHostBuilder()
.UseKestrel()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}
@koistya
Copy link
Author

koistya commented Jun 20, 2016

Example Query

Query Response

query {
  hello {
    world
  }
}
  

{
  "data": {
    "hello": "world"
  }
}
    

GraphQL Schema

JavaScript implementation C# implementation

var schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'RootQueryType',
    fields: {
      hello: {
        type: GraphQLString,
        resolve() {
          return 'world';
        }
      }
    }
  })
});
  

public class RootQueryType
{
    public Func<string> Hello { get; set; } = () => "world";
}

public class Schema
{
public RootQueryType Query { get; set; }
}

http://graphql.org/

@cluedtke
Copy link

cluedtke commented Jan 5, 2017

Could you share where you found the UseGraphQL extension method?

@alexsandro-xpt
Copy link

This is implementantion of that https://github.com/graphql-dotnet/graphql-dotnet ?

@mahald
Copy link

mahald commented Jun 9, 2017

i can't finde the useGraphQL in the package mentioned but im using this one: https://github.com/wesamco/ASP.Net-Core-GraphQL-Middleware

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment