Class: Rack::GraphiQL

Inherits:
Object
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/rack/graphiql.rb,
lib/rack/graphiql/version.rb

Constant Summary collapse

GRAPHIQL_VERSION =
'0.10.2'
FETCH_VERSION =
'2.0.1'
REACT_VERSION =
'15.5.4'
REACT_DOM_VERSION =
'15.5.4'
VERSION =
'0.1.1'

Instance Method Summary collapse

Constructor Details

#initialize(endpoint:) ⇒ GraphiQL

Returns a new instance of GraphiQL.



14
15
16
17
# File 'lib/rack/graphiql.rb', line 14

def initialize(endpoint:)
  @endpoint = endpoint
  @template = ERB.new(open(__FILE__).read.split("__END__\n").last)
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rack/graphiql.rb', line 19

def call(env)
  req = Rack::Request.new(env)
  graphiql_query = req.params['query']
  graphiql_variables = begin
                         JSON.pretty_generate(JSON.parse(req.params['variables'] || ''))
                       rescue JSON::ParserError
                         ''
                       end
  graphiql_operation_name = req.params['operationName']
  [200, {'Content-Type' => 'text/html'}, [@template.result(binding)]]
end