Class: GraphQL::Schema::TypeReducer
- Inherits:
-
Object
- Object
- GraphQL::Schema::TypeReducer
- Defined in:
- lib/graph_ql/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
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.find_all(types) ⇒ Object
Reduce all of ‘types` and return the combined result.
Instance Method Summary collapse
-
#initialize(type, existing_type_hash) ⇒ TypeReducer
constructor
A new instance of TypeReducer.
Constructor Details
#initialize(type, existing_type_hash) ⇒ TypeReducer
Returns a new instance of TypeReducer.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/graph_ql/schema/type_reducer.rb', line 5 def initialize(type, existing_type_hash) if [GraphQL::TypeKinds::NON_NULL, GraphQL::TypeKinds::LIST].include?(type.kind) @result = reduce_type(type.of_type, existing_type_hash) elsif existing_type_hash.has_key?(type.name) # been here, done that @result = existing_type_hash else @result = find_types(type, existing_type_hash.dup) end end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
4 5 6 |
# File 'lib/graph_ql/schema/type_reducer.rb', line 4 def result @result end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/graph_ql/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
17 18 19 20 21 |
# File 'lib/graph_ql/schema/type_reducer.rb', line 17 def self.find_all(types) types.reduce({}) do |memo, type| self.new(type, memo).result end end |