Class: GraphQL::Schema::TypeReducer

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/schema/type_reducer.rb

Overview

Starting from a given type, discover other types in the system by traversing that type’s fields, possible_types, etc

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, existing_type_hash) ⇒ TypeReducer

Returns a new instance of TypeReducer.



6
7
8
9
# File 'lib/graphql/schema/type_reducer.rb', line 6

def initialize(type, existing_type_hash)
  @type = type
  @existing_type_hash = existing_type_hash
end

Instance Attribute Details

#existing_type_hashObject (readonly)

Returns the value of attribute existing_type_hash.



4
5
6
# File 'lib/graphql/schema/type_reducer.rb', line 4

def existing_type_hash
  @existing_type_hash
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/graphql/schema/type_reducer.rb', line 4

def type
  @type
end

Class Method Details

.find_all(types) ⇒ Object

Reduce all of ‘types` and return the combined result



24
25
26
27
28
# File 'lib/graphql/schema/type_reducer.rb', line 24

def self.find_all(types)
  types.reduce({}) do |memo, type|
    self.new(type, memo).result
  end
end

Instance Method Details

#resultObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/graphql/schema/type_reducer.rb', line 11

def result
  @result ||= if type.respond_to?(:kind) && type.kind.wraps?
    reduce_type(type.of_type, existing_type_hash)
  elsif type.respond_to?(:name) && existing_type_hash.has_key?(type.name)
    # been here, done that
    existing_type_hash
  else
    validate_type(type)
    find_types(type, existing_type_hash.dup)
  end
end