Sha256: dec1120cdf4507319c935135aed90ceed711b2a8b229a44aef33745ea82696a0

Contents?: true

Size: 1.7 KB

Versions: 39

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

module GraphQL
  class Schema
    # This class joins an object type to an abstract type (interface or union) of which
    # it is a member.
    class TypeMembership
      # @return [Class<GraphQL::Schema::Object>]
      attr_accessor :object_type

      # @return [Class<GraphQL::Schema::Union>, Module<GraphQL::Schema::Interface>]
      attr_reader :abstract_type

      # Called when an object is hooked up to an abstract type, such as {Schema::Union.possible_types}
      # or {Schema::Object.implements} (for interfaces).
      #
      # @param abstract_type [Class<GraphQL::Schema::Union>, Module<GraphQL::Schema::Interface>]
      # @param object_type [Class<GraphQL::Schema::Object>]
      # @param options [Hash] Any options passed to `.possible_types` or `.implements`
      def initialize(abstract_type, object_type, **options)
        @abstract_type = abstract_type
        @object_type = object_type
        @options = options
      end

      # @return [Boolean] if false, {#object_type} will be treated as _not_ a member of {#abstract_type}
      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

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

      def path
        graphql_name
      end

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

      alias :type_class :itself
    end
  end
end

Version data entries

39 entries across 39 versions & 2 rubygems

Version Path
graphql-1.13.23 lib/graphql/schema/type_membership.rb
graphql-1.13.22 lib/graphql/schema/type_membership.rb
graphql-1.13.21 lib/graphql/schema/type_membership.rb
graphql-1.13.20 lib/graphql/schema/type_membership.rb
graphql-1.13.19 lib/graphql/schema/type_membership.rb
graphql-1.13.18 lib/graphql/schema/type_membership.rb
graphql-1.13.17 lib/graphql/schema/type_membership.rb
graphql-2.0.14 lib/graphql/schema/type_membership.rb
graphql-1.13.16 lib/graphql/schema/type_membership.rb
graphql-2.0.13 lib/graphql/schema/type_membership.rb
graphql-2.0.12 lib/graphql/schema/type_membership.rb
graphql-1.13.15 lib/graphql/schema/type_membership.rb
graphql-2.0.11 lib/graphql/schema/type_membership.rb
graphql-1.13.14 lib/graphql/schema/type_membership.rb
graphql-1.13.13 lib/graphql/schema/type_membership.rb
graphql-2.0.9 lib/graphql/schema/type_membership.rb
graphql-2.0.8 lib/graphql/schema/type_membership.rb
graphql-2.0.7 lib/graphql/schema/type_membership.rb
graphql_cody-1.13.0 lib/graphql/schema/type_membership.rb
graphql-1.13.12 lib/graphql/schema/type_membership.rb