Module: GraphQL::Schema::Loader

Extended by:
Loader
Included in:
Loader
Defined in:
lib/graphql/schema/loader.rb

Overview

You can use the result of Introspection::INTROSPECTION_QUERY to make a schema. This schema is missing some important details like resolve functions, but it does include the full type system, so you can use it to validate queries.

Instance Method Summary collapse

Instance Method Details

#load(introspection_result) ⇒ GraphQL::Schema

Create schema with the result of an introspection query.

Parameters:

Returns:

  • the schema described by input



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/graphql/schema/loader.rb', line 13

def load(introspection_result)
  schema = introspection_result.fetch("data").fetch("__schema")

  types = {}
  type_resolver = -> (type) { -> { resolve_type(types, type) } }

  schema.fetch("types").each do |type|
    next if type.fetch("name").start_with?("__")
    type_object = define_type(type, type_resolver)
    types[type_object.name] = type_object
  end

  query = types.fetch(schema.fetch("queryType").fetch("name"))

  Schema.new(query: query, types: types.values)
end