Class: GraphQL::UnionType
- Defined in:
- lib/graphql/union_type.rb
Overview
A Union is is a collection of object types which may appear in the same place.
The members of a union are declared with possible_types
.
A union itself has no fields; only its members have fields. So, when you query, you must use fragment spreads to access fields.
Instance Attribute Summary
Attributes inherited from BaseType
#default_relay, #default_scalar, #description, #introspection, #name
Instance Method Summary collapse
-
#include?(child_type_defn) ⇒ Boolean
True if
child_type_defn
is a member of this UnionType. -
#initialize ⇒ UnionType
constructor
A new instance of UnionType.
- #initialize_copy(other) ⇒ Object
- #kind ⇒ Object
-
#possible_types ⇒ Array<GraphQL::ObjectType>
Types which may be found in this union.
- #possible_types=(new_possible_types) ⇒ Object
Methods inherited from BaseType
#==, #coerce_input, #coerce_isolated_input, #coerce_isolated_result, #coerce_result, #connection_type, #default_relay?, #default_scalar?, #define_connection, #define_edge, #edge_type, #get_field, #introspection?, resolve_related_type, #resolve_type, #to_definition, #to_list_type, #to_non_null_type, #to_s, #unwrap, #valid_input?, #valid_isolated_input?, #validate_input, #validate_isolated_input
Methods included from Define::InstanceDefinable
Methods included from Define::NonNullWithBang
Constructor Details
#initialize ⇒ UnionType
Returns a new instance of UnionType.
30 31 32 33 34 |
# File 'lib/graphql/union_type.rb', line 30 def initialize super @dirty_possible_types = [] @clean_possible_types = nil end |
Instance Method Details
#include?(child_type_defn) ⇒ Boolean
Returns True if child_type_defn
is a member of this GraphQL::UnionType.
47 48 49 |
# File 'lib/graphql/union_type.rb', line 47 def include?(child_type_defn) possible_types.include?(child_type_defn) end |
#initialize_copy(other) ⇒ Object
36 37 38 39 40 |
# File 'lib/graphql/union_type.rb', line 36 def initialize_copy(other) super @clean_possible_types = nil @dirty_possible_types = other.dirty_possible_types.dup end |
#kind ⇒ Object
42 43 44 |
# File 'lib/graphql/union_type.rb', line 42 def kind GraphQL::TypeKinds::UNION end |
#possible_types ⇒ Array<GraphQL::ObjectType>
Returns Types which may be found in this union.
57 58 59 60 61 62 63 64 65 |
# File 'lib/graphql/union_type.rb', line 57 def possible_types @clean_possible_types ||= begin if @dirty_possible_types.respond_to?(:map) @dirty_possible_types.map { |type| GraphQL::BaseType.(type) } else @dirty_possible_types end end end |
#possible_types=(new_possible_types) ⇒ Object
51 52 53 54 |
# File 'lib/graphql/union_type.rb', line 51 def possible_types=(new_possible_types) @clean_possible_types = nil @dirty_possible_types = new_possible_types end |