Class: GraphQL::Query::TypeResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/query/type_resolver.rb

Overview

Given an object, a type name (from the query) and a type object, Return the type that should be used for ‘object` or Return `nil` if it’s a mismatch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, child_type, parent_type) ⇒ TypeResolver

Returns a new instance of TypeResolver.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/graphql/query/type_resolver.rb', line 6

def initialize(target, child_type, parent_type)
  @type = if child_type.nil?
    nil
  elsif parent_type.kind.union?
    parent_type.resolve_type(target)
  elsif child_type.kind.union? && child_type.include?(parent_type)
    parent_type
  elsif child_type.kind.interface?
    child_type.resolve_type(target)
  elsif child_type == parent_type
    parent_type
  else
    nil
  end
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/graphql/query/type_resolver.rb', line 5

def type
  @type
end