Module: ElasticGraph::Rack::GraphiQL

Defined in:
elasticgraph-rack/lib/elastic_graph/rack/graphiql.rb

Overview

A Rack application that serves both an ElasticGraph GraphQL endpoint and a GraphiQL IDE. This can be used for local development, mounted in a Rails application, or run in any other Rack-compatible context.

Examples:

Simple config.ru to run GraphiQL as a Rack application, targeting an ElasticGraph endpoint

require "elastic_graph/graphql"
require "elastic_graph/rack/graphiql"

graphql = ElasticGraph::GraphQL.from_yaml_file("config/settings/development.yaml")
run ElasticGraph::Rack::GraphiQL.new(graphql)

Class Method Summary collapse

Class Method Details

.new(graphql) ⇒ Rack::Builder

Builds a Rack application that serves both an ElasticGraph GraphQL endpoint and a GraphiQL IDE.

Parameters:

  • graphql (ElasticGraph::GraphQL)

    ElasticGraph GraphQL instance

Returns:

  • (Rack::Builder)

    built Rack application



31
32
33
34
35
36
37
38
39
40
41
# File 'elasticgraph-rack/lib/elastic_graph/rack/graphiql.rb', line 31

def self.new(graphql)
  graphql_endpoint = ElasticGraph::Rack::GraphQLEndpoint.new(graphql)

  ::Rack::Builder.new do
    use ::Rack::Static, urls: {"/" => "index.html"}, root: ::File.join(__dir__, "graphiql")

    map "/graphql" do
      run graphql_endpoint
    end
  end
end