Method: GraphQLServer#initialize

Defined in:
lib/graphql_server.rb

#initialize(*args, type_def: nil, resolver: nil, schema: nil, context: nil) ⇒ GraphQLServer

Initilizes GraphQLServer as a Rack app or middleware

This Rack middleware (or app) implements a spec-compliant GraphQL server which can be queried from any GraphQL client. It can be used with a provided GraphQL schema or can build one from a type definition and a resolver hash.

Parameters:

  • *args (Array<Object>)

    The first argument should be ‘app` when used as a middleware

  • String

    type_def A schema definition string, or a path to a file containing the definition

  • Hash

    resolver A hash with callables for handling field resolution

  • GraphQL::Schema

    schema Use this schema if ‘type_def` and `resolver` is nil

  • Hash

    context



19
20
21
22
23
# File 'lib/graphql_server.rb', line 19

def initialize(*args, type_def: nil, resolver: nil, schema: nil, context: nil)
  @app = args && args[0]
  @context = context
  @schema = type_def && resolver ? GraphQL::Schema.from_definition(type_def, default_resolve: resolver) : schema
end