class GraphQL::InternalRepresentation::Scope

fragments occur in inside one another.
The AST may be scoped to an array of types when two abstractly-typed
- ‘nil`
- An array of types
- A single concrete or abstract type
Scopes can be defined by:
{Scope} represents those types which selections may apply to.
At a point in the AST, selections may apply to one or more types.

def concrete_types

def concrete_types
  @concrete_types ||= if @abstract_type
    @query.possible_types(@type)
  else
    @types
  end
end

def each(&block)

so if this scope is defined by an abstract type, it gets yielded.
This uses the simplest possible expression of `self`,
Call the block for each type in `self`.
def each(&block)
  if @abstract_type
    yield(@type)
  else
    @types.each(&block)
  end
end

def enter(other_type_defn)

Returns:
  • (Scope) -

Parameters:
  • other_type_defn (GraphQL::BaseType, nil) --
def enter(other_type_defn)
  case other_type_defn
  when nil
    # The type wasn't found, who cares
    Scope.new(@query, nil)
  when @type
    # The condition is the same as current, so reuse self
    self
  when GraphQL::UnionType, GraphQL::InterfaceType
    # Make a new scope of the intersection between the previous & next conditions
    new_types = @query.possible_types(other_type_defn) & concrete_types
    Scope.new(@query, new_types)
  when GraphQL::BaseType
    # If this type is valid within the current scope,
    # return a new scope of _exactly_ this type.
    # Otherwise, this type is out-of-scope so the scope is null.
    if concrete_types.include?(other_type_defn)
      Scope.new(@query, other_type_defn)
    else
      Scope.new(@query, nil)
    end
  else
    raise "Unexpected scope: #{other_type_defn.inspect}"
  end
end

def initialize(query, type_defn)

Parameters:
  • type_defn (GraphQL::BaseType, Array, nil) --
  • query (GraphQL::Query) --
def initialize(query, type_defn)
  @query = query
  @type = type_defn
  @abstract_type = false
  @types = case type_defn
  when Array
    type_defn
  when GraphQL::BaseType
    @abstract_type = true
    nil
  when nil
    NO_TYPES
  else
    raise "Unexpected scope type: #{type_defn}"
  end
end