Module: GraphQL::Schema::Loader
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.
Constant Summary collapse
- NullResolveType =
->(type, obj, ctx) { raise(NotImplementedError, "This schema was loaded from string, so it can't resolve types for objects") }
- NullScalarCoerce =
->(val, _ctx) { val }
Instance Method Summary collapse
-
#load(introspection_result) ⇒ GraphQL::Schema
deprecated
Deprecated.
Use from_introspection instead
Instance Method Details
#load(introspection_result) ⇒ GraphQL::Schema
Deprecated.
Use GraphQL::Schema.from_introspection instead
Create schema with the result of an introspection query.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/graphql/schema/loader.rb', line 15 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 kargs = { orphan_types: types.values, resolve_type: NullResolveType } [:query, :mutation, :subscription].each do |root| type = schema["#{root}Type"] kargs[root] = types.fetch(type.fetch("name")) if type end Schema.define(**kargs, raise_definition_error: true) end |