Class: GraphQL::Stitching::Util
- Inherits:
-
Object
- Object
- GraphQL::Stitching::Util
- Defined in:
- lib/graphql/stitching/util.rb
Defined Under Namespace
Classes: TypeStructure
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.
-
.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
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/graphql/stitching/util.rb', line 52 def (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.tap(&:uniq!) end |
.flatten_type_structure(type) ⇒ Object
builds a single-dimensional representation of a wrapped type structure
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/graphql/stitching/util.rb', line 28 def flatten_type_structure(type) structure = [] while type.list? structure << TypeStructure.new( list: true, null: !type.non_null?, name: nil, ) type = unwrap_non_null(type).of_type end structure << TypeStructure.new( 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
17 18 19 |
# File 'lib/graphql/stitching/util.rb', line 17 def is_leaf_type?(type) type.kind.scalar? || type.kind.enum? end |
.unwrap_non_null(type) ⇒ Object
strips non-null wrappers from a type
22 23 24 25 |
# File 'lib/graphql/stitching/util.rb', line 22 def unwrap_non_null(type) type = type.of_type while type.non_null? type end |