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 Schema::Union.possible_types or Schema::Object.implements (for interfaces).

Parameters

  • abstract_type (Class<GraphQL::Schema::Union>, Module<GraphQL::Schema::Interface>)
  • object_type (Class<GraphQL::Schema::Object>)
  • options (Hash) — Any options passed to .possible_types or .implements

:call-seq:

initialize(Class[GraphQL::Schema::Union] | Module[GraphQL::Schema::Interface] abstract_type, Class[GraphQL::Schema::Object] object_type, Hash **options)


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

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

Instance Attribute Details

#abstract_type ⇒ Object (readonly)

Returns

  • Class<GraphQL::Schema::Union>, Module<GraphQL::Schema::Interface>


18
19
20
# File 'lib/graphql/schema/type_membership.rb', line 18

def abstract_type
  @abstract_type
end

#object_type ⇒ Object

Returns

  • Class<GraphQL::Schema::Object>


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

def object_type
  @object_type
end

#options ⇒ Object (readonly)

Returns

  • Hash


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

def options
  @options
end

Instance Method Details

#graphql_name ⇒ Object



54
55
56
# File 'lib/graphql/schema/type_membership.rb', line 54

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

#inspect ⇒ Object



62
63
64
# File 'lib/graphql/schema/type_membership.rb', line 62

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

#path ⇒ Object



58
59
60
# File 'lib/graphql/schema/type_membership.rb', line 58

def path
  graphql_name
end

#type_class ⇒ Object



66
67
68
# File 'lib/graphql/schema/type_membership.rb', line 66

def type_class
  self
end

#visible?(ctx) ⇒ Boolean

Returns

:call-seq:

visible?(ctx) -> bool

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/graphql/schema/type_membership.rb', line 48

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