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:



23
24
25
26
27
# File 'lib/graphql/schema/type_membership.rb', line 23

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

#optionsHash (readonly)

Returns:

  • (Hash)


15
16
17
# File 'lib/graphql/schema/type_membership.rb', line 15

def options
  @options
end

Instance Method Details

#graphql_nameObject



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

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

#inspectObject



44
45
46
# File 'lib/graphql/schema/type_membership.rb', line 44

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

#pathObject



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

def path
  graphql_name
end

#visible?(ctx) ⇒ Boolean

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

Returns:



30
31
32
33
34
# File 'lib/graphql/schema/type_membership.rb', line 30

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