class GraphQL::Schema


end
orphan_types ImageType, AudioType
# If types are only connected by way of interfaces, they must be added here
rescue_from(ActiveRecord::RecordNotFound) { “Not found” }
middleware PermissionMiddleware
query QueryType
MySchema = GraphQL::Schema.define do
@example defining a schema
A schema accepts a ‘Relay::GlobalNodeIdentification` instance for use with Relay IDs.
each apply to corresponding root types.
`query_execution_strategy`, `mutation_execution_strategy` and `subscription_execution_strategy`
Schemas can specify how queries should be executed against them.
(These configurations can be overridden by specific calls to {Schema#execute})
Schemas can restrict large incoming queries with `max_depth` and `max_complexity` configurations.
Any undiscoverable types may be provided with the `types` configuration.
The schema will traverse the tree of fields & types, using those as starting points.
Schemas start with root types, {Schema#query}, {Schema#mutation} and {Schema#subscription}.
- middleware for interacting with execution
- execution strategies for running incoming queries
- query analyzers for assessing incoming queries (including max depth & max complexity restrictions)
- types for exposing your application
The {Schema} contains:
A GraphQL schema which may be queried with {GraphQL::Query}.

def self.from_definition(definition_string)

Returns:
  • (GraphQL::Schema) - the schema described by `document`

Parameters:
  • definition_string () -- String A schema definition string
def self.from_definition(definition_string)
  GraphQL::Schema::BuildFromDefinition.from_definition(definition_string)
end

def self.from_introspection(introspection_result)

Returns:
  • (GraphQL::Schema) - the schema described by `input`

Parameters:
  • introspection_result (Hash) -- A response from {GraphQL::Introspection::INTROSPECTION_QUERY}
def self.from_introspection(introspection_result)
  GraphQL::Schema::Loader.load(introspection_result)
end

def define(**kwargs, &block)

def define(**kwargs, &block)
  super
  ensure_defined
  all_types = orphan_types + [query, mutation, subscription, GraphQL::Introspection::SchemaType]
  @types = GraphQL::Schema::ReduceTypes.reduce(all_types.compact)
  @instrumented_field_map = InstrumentedFieldMap.new(self)
  field_instrumenters = @instrumenters[:field]
  types.each do |type_name, type|
    if type.kind.fields?
      type.all_fields.each do |field_defn|
        instrumented_field_defn = field_instrumenters.reduce(field_defn) do |defn, inst|
          inst.instrument(type, defn)
        end
        @instrumented_field_map.set(type.name, field_defn.name, instrumented_field_defn)
      end
    end
  end
  # Assert that all necessary configs are present:
  validation_error = Validation.validate(self)
  validation_error && raise(NotImplementedError, validation_error)
  nil
end

def execute(*args)

Returns:
  • (Hash) - query result, ready to be serialized as JSON
def execute(*args)
  query_obj = GraphQL::Query.new(self, *args)
  query_obj.result
end

def execution_strategy_for_operation(operation)

def execution_strategy_for_operation(operation)
  case operation
  when "query"
    query_execution_strategy
  when "mutation"
    mutation_execution_strategy
  when "subscription"
    subscription_execution_strategy
  else
    raise ArgumentError, "unknown operation type: #{operation}"
  end
end

def get_field(parent_type, field_name)

Returns:
  • (GraphQL::Field, nil) - The field named `field_name` on `parent_type`

Other tags:
    See: [GraphQL::Schema::Warden] - Restricted access to members of a schema
def get_field(parent_type, field_name)
  defined_field = @instrumented_field_map.get(parent_type.name, field_name)
  if defined_field
    defined_field
  elsif field_name == "__typename"
    GraphQL::Introspection::TypenameField.create(parent_type)
  elsif field_name == "__schema" && parent_type == query
    GraphQL::Introspection::SchemaField.create(self)
  elsif field_name == "__type" && parent_type == query
    GraphQL::Introspection::TypeByNameField.create(self)
  else
    nil
  end
end

def id_from_object(object, type, ctx)

Returns:
  • (String) - a unique identifier for `object` which clients can use to refetch it

Parameters:
  • ctx (GraphQL::Query::Context) -- the context for the current query
  • type (GraphQL::BaseType) -- The current type definition
  • object (Any) -- An application object
def id_from_object(object, type, ctx)
  if @id_from_object_proc.nil?
    raise(NotImplementedError, "Can't generate an ID for #{object.inspect} of type #{type}, schema's `id_from_object` must be defined")
  else
    @id_from_object_proc.call(object, type, ctx)
  end
end

def id_from_object=(new_proc)

Parameters:
  • new_proc (#call) -- A new callable for generating unique IDs
def id_from_object=(new_proc)
  @id_from_object_proc = new_proc
end

def initialize

Parameters:
  • types (Array) -- additional types to include in this schema
  • max_depth (Integer) -- maximum query nesting (if it's greater, raise an error)
  • subscription (GraphQL::ObjectType) -- the subscription root for the schema
  • mutation (GraphQL::ObjectType) -- the mutation root for the schema
  • query (GraphQL::ObjectType) -- the query root for the schema
def initialize
  @orphan_types = []
  @directives = DIRECTIVES.reduce({}) { |m, d| m[d.name] = d; m }
  @static_validator = GraphQL::StaticValidation::Validator.new(schema: self)
  @middleware = []
  @query_analyzers = []
  @resolve_type_proc = nil
  @object_from_id_proc = nil
  @id_from_object_proc = nil
  @instrumenters = Hash.new { |h, k| h[k] = [] }
  # Default to the built-in execution strategy:
  @query_execution_strategy = GraphQL::Query::SerialExecution
  @mutation_execution_strategy = GraphQL::Query::SerialExecution
  @subscription_execution_strategy = GraphQL::Query::SerialExecution
end

def object_from_id(id, ctx)

Returns:
  • (Any) - The application object identified by `id`

Parameters:
  • ctx (GraphQL::Query::Context) -- The context for the current query
  • id (String) -- A unique identifier, provided previously by this GraphQL schema
def object_from_id(id, ctx)
  if @object_from_id_proc.nil?
    raise(NotImplementedError, "Can't fetch an object for id \"#{id}\" because the schema's `object_from_id (id, ctx) -> { ... }` function is not defined")
  else
    @object_from_id_proc.call(id, ctx)
  end
end

def object_from_id=(new_proc)

Parameters:
  • new_proc (#call) -- A new callable for fetching objects by ID
def object_from_id=(new_proc)
  @object_from_id_proc = new_proc
end

def possible_types(type_defn)

Returns:
  • (Array) - types which belong to `type_defn` in this schema

Parameters:
  • type_defn (GraphQL::InterfaceType, GraphQL::UnionType) -- the type whose members you want to retrieve

Other tags:
    See: [GraphQL::Schema::Warden] - Restricted access to members of a schema
def possible_types(type_defn)
  @possible_types ||= GraphQL::Schema::PossibleTypes.new(self)
  @possible_types.possible_types(type_defn)
end

def remove_handler(*args, &block)

def remove_handler(*args, &block)
  rescue_middleware.remove_handler(*args, &block)
end

def rescue_from(*args, &block)

def rescue_from(*args, &block)
  rescue_middleware.rescue_from(*args, &block)
end

def rescue_middleware

(Don't add it if it's not used)
Lazily create a middleware and add it to the schema
def rescue_middleware
  @rescue_middleware ||= begin
    middleware = GraphQL::Schema::RescueMiddleware.new
    @middleware << middleware
    middleware
  end
end

def resolve_type(object, ctx)

Returns:
  • (GraphQL::ObjectType) - The type for exposing `object` in GraphQL

Parameters:
  • ctx (GraphQL::Query::Context) -- The context for the current query
  • object (Any) -- An application object which GraphQL is currently resolving on

Other tags:
    See: [GraphQL::Schema::Warden] - Restricted access to members of a schema
def resolve_type(object, ctx)
  if @resolve_type_proc.nil?
    raise(NotImplementedError, "Can't determine GraphQL type for: #{object.inspect}, define `resolve_type (obj, ctx) -> { ... }` inside `Schema.define`.")
  end
  type_result = @resolve_type_proc.call(object, ctx)
  if type_result.nil?
    nil
  elsif !type_result.is_a?(GraphQL::BaseType)
    type_str = "#{type_result} (#{type_result.class.name})"
    raise "resolve_type(#{object}) returned #{type_str}, but it should return a GraphQL type"
  else
    type_result
  end
end

def resolve_type=(new_resolve_type_proc)

def resolve_type=(new_resolve_type_proc)
  @resolve_type_proc = new_resolve_type_proc
end

def root_type_for_operation(operation)

def root_type_for_operation(operation)
  case operation
  when "query"
    query
  when "mutation"
    mutation
  when "subscription"
    subscription
  else
    raise ArgumentError, "unknown operation type: #{operation}"
  end
end

def type_from_ast(ast_node)

def type_from_ast(ast_node)
  GraphQL::Schema::TypeExpression.build_type(self.types, ast_node)
end