Class: GraphQL::Stitching::Util
- Inherits:
-
Object
- Object
- GraphQL::Stitching::Util
- Defined in:
- lib/graphql/stitching/util.rb
Class Method Summary collapse
-
.get_list_structure(type) ⇒ Object
gets a deep structural description of a list value type.
-
.get_named_type(type) ⇒ Object
gets the named type at the bottom of a non-null/list wrapper chain.
- .get_named_type_for_field_node(schema, parent_type, node) ⇒ Object
-
.get_possible_types(schema, parent_type) ⇒ Object
Gets all objects and interfaces that implement a given interface.
-
.is_leaf_type?(type) ⇒ Boolean
Specifies if a type is a leaf node (no children).
Class Method Details
.get_list_structure(type) ⇒ Object
gets a deep structural description of a list value type
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/graphql/stitching/util.rb', line 16 def self.get_list_structure(type) structure = [] previous = nil while type.respond_to?(:of_type) if type.is_a?(GraphQL::Schema::List) structure.push(previous.is_a?(GraphQL::Schema::NonNull) ? "non_null_list" : "list") end if structure.any? previous = type if !type.of_type.respond_to?(:of_type) structure.push(previous.is_a?(GraphQL::Schema::NonNull) ? "non_null_element" : "element") end end type = type.of_type end structure end |
.get_named_type(type) ⇒ Object
gets the named type at the bottom of a non-null/list wrapper chain
8 9 10 11 12 13 |
# File 'lib/graphql/stitching/util.rb', line 8 def self.get_named_type(type) while type.respond_to?(:of_type) type = type.of_type end type end |
.get_named_type_for_field_node(schema, parent_type, node) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/graphql/stitching/util.rb', line 54 def self.get_named_type_for_field_node(schema, parent_type, node) if node.name == "__schema" && parent_type == schema.query schema.types["__Schema"] # type mapped to phantom introspection field else Util.get_named_type(parent_type.fields[node.name].type) end end |
.get_possible_types(schema, parent_type) ⇒ Object
Gets all objects and interfaces that implement a given interface
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/graphql/stitching/util.rb', line 35 def self.get_possible_types(schema, parent_type) return [parent_type] unless parent_type.kind.abstract? return parent_type.possible_types if parent_type.kind.union? result = [] schema.types.values.each do |type| next unless type <= GraphQL::Schema::Interface && type != parent_type next unless type.interfaces.include?(parent_type) result << type result.push(*get_possible_types(schema, type)) if type.kind.interface? end result.uniq end |
.is_leaf_type?(type) ⇒ Boolean
Specifies if a type is a leaf node (no children)
50 51 52 |
# File 'lib/graphql/stitching/util.rb', line 50 def self.is_leaf_type?(type) type.kind.scalar? || type.kind.enum? end |