Class: GraphQL::Stitching::Util
- Inherits:
-
Object
- Object
- GraphQL::Stitching::Util
- Defined in:
- lib/graphql/stitching/util.rb
Class Method Summary collapse
-
.expand_abstract_type(schema, parent_type) ⇒ Object
expands interfaces and unions to an array of their memberships like ‘schema.possible_types`, but includes child interfaces.
-
.flatten_type_structure(type) ⇒ Object
builds a single-dimensional representation of a wrapped type structure.
-
.is_leaf_type?(type) ⇒ Boolean
specifies if a type is a primitive leaf value.
-
.named_type_for_field_node(schema, parent_type, node) ⇒ Object
gets a named type for a field node, including hidden root introspections.
-
.unwrap_non_null(type) ⇒ Object
strips non-null wrappers from a type.
Class Method Details
.expand_abstract_type(schema, parent_type) ⇒ Object
expands interfaces and unions to an array of their memberships like ‘schema.possible_types`, but includes child interfaces
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/graphql/stitching/util.rb', line 51 def self.(schema, parent_type) return [] 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(*(schema, type)) if type.kind.interface? end result.uniq end |
.flatten_type_structure(type) ⇒ Object
builds a single-dimensional representation of a wrapped type structure
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/graphql/stitching/util.rb', line 18 def self.flatten_type_structure(type) structure = [] while type.list? structure << { list: true, null: !type.non_null?, name: nil, } type = unwrap_non_null(type).of_type end structure << { list: false, null: !type.non_null?, name: type.unwrap.graphql_name, } structure end |
.is_leaf_type?(type) ⇒ Boolean
specifies if a type is a primitive leaf value
7 8 9 |
# File 'lib/graphql/stitching/util.rb', line 7 def self.is_leaf_type?(type) type.kind.scalar? || type.kind.enum? end |
.named_type_for_field_node(schema, parent_type, node) ⇒ Object
gets a named type for a field node, including hidden root introspections
41 42 43 44 45 46 47 |
# File 'lib/graphql/stitching/util.rb', line 41 def self.named_type_for_field_node(schema, parent_type, node) if node.name == "__schema" && parent_type == schema.query schema.types["__Schema"] else parent_type.fields[node.name].type.unwrap end end |
.unwrap_non_null(type) ⇒ Object
strips non-null wrappers from a type
12 13 14 15 |
# File 'lib/graphql/stitching/util.rb', line 12 def self.unwrap_non_null(type) type = type.of_type while type.non_null? type end |