GraphQlRethinkDbHttp

Framework to create web apps with GraphQL and RethinkDb, lite version refactored to get rid of asp.net


Keywords
graphql, rethinkdb
Install
Install-Package GraphQlRethinkDbHttp -Version 1.0.2

Documentation

GraphQlRethinkDbTemplate

========

Getting started

Start with an ASP.NET Core web application. Upgrade the project to dotnet core 2.0.

Startup.cs

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    BaseHandler.Setup(
        app,
        env,
        new DatabaseName(Program.DatabaseName),
        new DatabaseUrl("localhost"),
        new GraphQlDefaultHandler<Query,Mutation>(),
        new ImageFileHandler(),  // Optional, if you want to serve images from the api
        new AudioFileHandler()); // Optional, if you want to stream audio from the api
}

Query and Mutation

[ImplementViewer(OperationType.Query)]
public class Query
{
    [Description("Get data by id")]
    public Task<SomeDataClass> Data(UserContext context, Id id)
    {
        var data = context.Get<SomeDataClass>(id);
        return Task.FromResult(data);
    }
}
[ImplementViewer(OperationType.Mutation)]
public class Mutation
{
    public DefaultResult<SomeDataClass> AddData(
    UserContext context,
    NonNull<string> text)
    {
        var data = new SomeDataClass(text);
        var ret = context.AddDefault(data);
        return new DefaultResult<SomeDataClass>(ret);
    }
}

Data

public class SomeDataClass : NodeBase<SomeDataClass>
{
    public SomeDataClass(string text)
    {
        Text = text;
    }

    public string Text { get; }
}