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 collapse
- 
  
    
      #resolve_type_proc  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute resolve_type_proc.
 
Attributes inherited from BaseType
#ast_node, #default_relay, #default_scalar, #description, #introspection, #name
Instance Method Summary collapse
- 
  
    
      #get_possible_type(type_name, ctx)  ⇒ GraphQL::ObjectType? 
    
    
  
  
  
  
  
  
  
  
  
    
Get a possible type of this UnionType by type name.
 - 
  
    
      #include?(child_type_defn)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
True if
child_type_defnis a member of this UnionType. - 
  
    
      #initialize  ⇒ UnionType 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of UnionType.
 - 
  
    
      #initialize_copy(other)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #kind  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #possible_type?(type, ctx)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Check if a type is a possible type of this UnionType.
 - 
  
    
      #possible_types  ⇒ Array<GraphQL::ObjectType> 
    
    
  
  
  
  
  
  
  
  
  
    
Types which may be found in this union.
 - 
  
    
      #possible_types=(new_possible_types)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #resolve_type(value, ctx)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #resolve_type=(new_resolve_type_proc)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
 
Methods inherited from BaseType
#==, #coerce_input, #coerce_isolated_input, #coerce_isolated_result, #coerce_result, #default_relay?, #default_scalar?, #get_field, #introspection?, #list?, #non_null?, resolve_related_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 Relay::TypeExtensions
#connection_type, #define_connection, #define_edge, #edge_type
Methods included from Define::InstanceDefinable
Methods included from Define::NonNullWithBang
Constructor Details
#initialize ⇒ UnionType
Returns a new instance of UnionType
      32 33 34 35 36 37  | 
    
      # File 'lib/graphql/union_type.rb', line 32 def initialize super @dirty_possible_types = [] @clean_possible_types = nil @resolve_type_proc = nil end  | 
  
Instance Attribute Details
#resolve_type_proc ⇒ Object
Returns the value of attribute resolve_type_proc
      30 31 32  | 
    
      # File 'lib/graphql/union_type.rb', line 30 def resolve_type_proc @resolve_type_proc end  | 
  
Instance Method Details
#get_possible_type(type_name, ctx) ⇒ GraphQL::ObjectType?
Get a possible type of this GraphQL::UnionType by type name
      74 75 76 77  | 
    
      # File 'lib/graphql/union_type.rb', line 74 def get_possible_type(type_name, ctx) type = ctx.query.get_type(type_name) type if type && ctx.query.schema.possible_types(self).include?(type) end  | 
  
#include?(child_type_defn) ⇒ Boolean
Returns True if child_type_defn is a member of this GraphQL::UnionType
      50 51 52  | 
    
      # File 'lib/graphql/union_type.rb', line 50 def include?(child_type_defn) possible_types.include?(child_type_defn) end  | 
  
#initialize_copy(other) ⇒ Object
      39 40 41 42 43  | 
    
      # File 'lib/graphql/union_type.rb', line 39 def initialize_copy(other) super @clean_possible_types = nil @dirty_possible_types = other.dirty_possible_types.dup end  | 
  
#kind ⇒ Object
      45 46 47  | 
    
      # File 'lib/graphql/union_type.rb', line 45 def kind GraphQL::TypeKinds::UNION end  | 
  
#possible_type?(type, ctx) ⇒ Boolean
Check if a type is a possible type of this GraphQL::UnionType
      83 84 85 86  | 
    
      # File 'lib/graphql/union_type.rb', line 83 def possible_type?(type, ctx) type_name = type.is_a?(String) ? type : type.graphql_name !get_possible_type(type_name, ctx).nil? end  | 
  
#possible_types ⇒ Array<GraphQL::ObjectType>
Returns Types which may be found in this union
      60 61 62 63 64 65 66 67 68  | 
    
      # File 'lib/graphql/union_type.rb', line 60 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
      54 55 56 57  | 
    
      # File 'lib/graphql/union_type.rb', line 54 def possible_types=(new_possible_types) @clean_possible_types = nil @dirty_possible_types = new_possible_types end  | 
  
#resolve_type(value, ctx) ⇒ Object
      88 89 90  | 
    
      # File 'lib/graphql/union_type.rb', line 88 def resolve_type(value, ctx) ctx.query.resolve_type(self, value) end  | 
  
#resolve_type=(new_resolve_type_proc) ⇒ Object
      92 93 94  | 
    
      # File 'lib/graphql/union_type.rb', line 92 def resolve_type=(new_resolve_type_proc) @resolve_type_proc = new_resolve_type_proc end  |