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.
Instance Method Summary collapse
-
#load(introspection_result) ⇒ GraphQL::Schema
Create schema with the result of an introspection query.
Instance Method Details
#load(introspection_result) ⇒ GraphQL::Schema
Create schema with the result of an introspection query.
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 |