Class: GraphQL::Schema::TypeMembership
- Inherits:
-
Object
- Object
- GraphQL::Schema::TypeMembership
- 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
-
#abstract_type ⇒ Class<GraphQL::Schema::Union>, Module<GraphQL::Schema::Interface>
readonly
-
#object_type ⇒ Class<GraphQL::Schema::Object>
Instance Method Summary collapse
-
#graphql_name ⇒ Object
-
#initialize(abstract_type, object_type, **options) ⇒ TypeMembership
constructor
Called when an object is hooked up to an abstract type, such as Union.possible_types or Schema::Object.implements (for interfaces).
-
#inspect ⇒ Object
-
#path ⇒ Object
-
#visible?(ctx) ⇒ Boolean
If false, #object_type will be treated as not a member of #abstract_type.
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).
20 21 22 23 24 |
# File 'lib/graphql/schema/type_membership.rb', line 20 def initialize(abstract_type, object_type, **) @abstract_type = abstract_type @object_type = object_type @options = end |
Instance Attribute Details
#abstract_type ⇒ Class<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_type ⇒ Class<GraphQL::Schema::Object>
9 10 11 |
# File 'lib/graphql/schema/type_membership.rb', line 9 def object_type @object_type end |
Instance Method Details
#graphql_name ⇒ Object
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 |
#inspect ⇒ Object
41 42 43 |
# File 'lib/graphql/schema/type_membership.rb', line 41 def inspect "#<#{self.class} #{@object_type.inspect} => #{@abstract_type.inspect}>" end |
#path ⇒ Object
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.
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 |