This is a simple spec-compliant GraphQL rack application and middleware based on the graphql gem. Since it's built with Rack, it can be mounted with most ruby web servers.

Install the gem:

gem install graphql-server

Using the server

As a standalone application

# app.ru
require 'graphql_server'

type_def = "  type Query {\n    hello: String\n  }\n"

resolver = {
  "Query" => {
    "hello" => Proc.new { "world" }
  }
}

run GraphqlServer.new(type_def: type_def, resolver: resolver)

Start using rackup

rackup app.ru

As a middleware in your application

# app.ru
require 'graphql_server'

type_def = ...
resolver = ...

use GraphqlServer, type_def: type_def, resolver: resolver, path: '/graphql'

Start using rackup

rackup app.ru

Options

Schema

You can get started fast by writing a type defintions and a resolver hash

GraphqlServer.new(type_def: type_def, resolver: resolver)

You can also provide your own schema

GraphqlServer.new(schema: schema)

See the examples folder for more details

Middleware

When using as a middleware, you can specify the path to mount the graphql endpoint (defaults to /)

use GraphqlServer, type_def: type_def, resolver: resolver, path: '/graphql'