Class: GraphQL::Schema::Union

Inherits:
Member
  • Object
show all
Extended by:
Member::HasUnresolvedTypeError
Defined in:
lib/graphql/schema/union.rb

Constant Summary

Constants included from Member::GraphQLTypeNames

Member::GraphQLTypeNames::Boolean, Member::GraphQLTypeNames::ID, Member::GraphQLTypeNames::Int

Instance Attribute Summary

Attributes included from Member::BaseDSLMethods

#default_graphql_name, #graphql_name

Attributes included from Member::RelayShortcuts

#connection_type, #connection_type_class, #edge_type, #edge_type_class

Attributes included from Member::HasAstNode

#ast_node

Class Method Summary collapse

Methods inherited from Member

authorizes?

Methods included from Member::BaseDSLMethods

#authorized?, #comment, #default_relay?, #description, #introspection, #introspection?, #mutation, #visible?

Methods included from FindInheritedValue

extended, included

Methods included from Member::BaseDSLMethods::ConfigurationExtension

#inherited

Methods included from Member::TypeSystemHelpers

#initialize, #kind, #list?, #non_null?, #to_list_type, #to_non_null_type, #to_type_signature

Methods included from Member::Scoped

#inherited, #reauthorize_scoped_objects, #scope_items

Methods included from Member::HasPath

#path

Methods included from Member::HasAstNode

extended, #inherited

Methods included from Member::HasDirectives

add_directive, #directive, #directives, extended, get_directives, #inherited, #remove_directive, remove_directive

Class Method Details

.all_possible_types ⇒ Object



33
34
35
# File 'lib/graphql/schema/union.rb', line 33

def all_possible_types
  type_memberships.map(&:object_type)
end

.assign_type_membership_object_type(object_type) ⇒ Object

Update a type membership whose .object_type is a string or late-bound type so that the type membership's .object_type is the given object_type. (This is used for updating the union after the schema as lazily loaded the union member.)



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/graphql/schema/union.rb', line 56

def assign_type_membership_object_type(object_type) # :nodoc:
  assert_valid_union_member(object_type)
  type_memberships.each { |tm|
    possible_type = tm.object_type
    if possible_type.is_a?(String) && (possible_type == object_type.name)
      # This is a match of Ruby class names, not graphql names,
      # since strings are used to refer to constants.
      tm.object_type = object_type
    elsif possible_type.is_a?(LateBoundType) && possible_type.graphql_name == object_type.graphql_name
      tm.object_type = object_type
    end
  }
  nil
end

.inherited(child_class) ⇒ Object



10
11
12
13
# File 'lib/graphql/schema/union.rb', line 10

def inherited(child_class)
  add_unresolved_type_error(child_class)
  super
end

.kind ⇒ Object



45
46
47
# File 'lib/graphql/schema/union.rb', line 45

def kind
  GraphQL::TypeKinds::UNION
end

.possible_types(*types, context: GraphQL::Query::NullContext.instance, **options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/graphql/schema/union.rb', line 15

def possible_types(*types, context: GraphQL::Query::NullContext.instance, **options)
  if !types.empty?
    types.each do |t|
      assert_valid_union_member(t)
      type_memberships << type_membership_class.new(self, t, **options)
    end
  else
    visible_types = []
    warden = Warden.from_context(context)
    type_memberships.each do |type_membership|
      if warden.visible_type_membership?(type_membership, context)
        visible_types << type_membership.object_type
      end
    end
    visible_types
  end
end

.type_membership_class(membership_class = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/graphql/schema/union.rb', line 37

def type_membership_class(membership_class = nil)
  if membership_class
    @type_membership_class = membership_class
  else
    @type_membership_class || find_inherited_value(:type_membership_class, GraphQL::Schema::TypeMembership)
  end
end

.type_memberships ⇒ Object



49
50
51
# File 'lib/graphql/schema/union.rb', line 49

def type_memberships
  @type_memberships ||= []
end