Class: GraphQL::Schema::TypeMembership

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/schema/type_membership.rb

Overview

This class joins an object type to an abstract type (interface or union) of which it is a member.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(abstract_type, object_type, **options) ⇒ TypeMembership

Called when an object is hooked up to an abstract type, such as Union.possible_types or Schema::Object.implements (for interfaces).

Parameters:



20
21
22
23
24
# File 'lib/graphql/schema/type_membership.rb', line 20

def initialize(abstract_type, object_type, **options)
  @abstract_type = abstract_type
  @object_type = object_type
  @options = options
end

Instance Attribute Details

#abstract_typeClass<GraphQL::Schema::Union>, Module<GraphQL::Schema::Interface> (readonly)



12
13
14
# File 'lib/graphql/schema/type_membership.rb', line 12

def abstract_type
  @abstract_type
end

#object_typeClass<GraphQL::Schema::Object>

Returns:



9
10
11
# File 'lib/graphql/schema/type_membership.rb', line 9

def object_type
  @object_type
end

Instance Method Details

#graphql_nameObject



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

def graphql_name
  "#{@object_type.graphql_name}.#{@abstract_type.kind.interface? ? "implements" : "belongsTo" }.#{@abstract_type.graphql_name}"
end

#inspectObject



41
42
43
# File 'lib/graphql/schema/type_membership.rb', line 41

def inspect
  "#<#{self.class} #{@object_type.inspect} => #{@abstract_type.inspect}>"
end

#pathObject



37
38
39
# File 'lib/graphql/schema/type_membership.rb', line 37

def path
  graphql_name
end

#visible?(ctx) ⇒ Boolean

Returns if false, #object_type will be treated as not a member of #abstract_type.

Returns:



27
28
29
30
31
# File 'lib/graphql/schema/type_membership.rb', line 27

def visible?(ctx)
  warden = Warden.from_context(ctx)
  (@object_type.respond_to?(:visible?) ? warden.visible_type?(@object_type, ctx) : true) &&
    (@abstract_type.respond_to?(:visible?) ? warden.visible_type?(@abstract_type, ctx) : true)
end