Sha256: 754f40669d93e3dabfd7d0816fe0c774e2f35aeca68cff6c7bb750b3292d6866

Contents?: true

Size: 1.69 KB

Versions: 27

Compression:

Stored size: 1.69 KB

Contents

module GraphQL
  module Execution
    # GraphQL object `{value, current_type}` can be cast to `potential_type` when:
    # - `current_type == potential_type`
    # - `current_type` is a union and it contains `potential_type`
    # - `potential_type` is a union and it contains `current_type`
    # - `current_type` is an interface and `potential_type` implements it
    # - `potential_type` is an interface and `current_type` implements it
    module Typecast
      # While `value` is exposed by GraphQL as an instance of `current_type`,
      # should it _also_ be treated as an instance of `potential_type`?
      #
      # This is used for checking whether fragments apply to an object.
      #
      # @param [Object] the value which GraphQL is currently exposing
      # @param [GraphQL::BaseType] the type which GraphQL is using for `value` now
      # @param [GraphQL::BaseType] can `value` be exposed using this type?
      # @param [GraphQL::Query::Context] the context for the current query
      # @return [Boolean] true if `value` be evaluated as a `potential_type`
      def self.compatible?(current_type, potential_type, query_ctx)
        if current_type == potential_type
          true
        elsif current_type.kind.union?
          current_type.possible_types.include?(potential_type)
        elsif potential_type.kind.union?
          potential_type.include?(current_type)
        elsif current_type.kind.interface? && potential_type.kind.object?
          potential_type.interfaces.include?(current_type)
        elsif potential_type.kind.interface? && current_type.kind.object?
          current_type.interfaces.include?(potential_type)
        else
          false
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
graphql-1.2.6 lib/graphql/execution/typecast.rb
graphql-1.2.5 lib/graphql/execution/typecast.rb
graphql-1.2.4 lib/graphql/execution/typecast.rb
graphql-1.2.3 lib/graphql/execution/typecast.rb
graphql-1.2.2 lib/graphql/execution/typecast.rb
graphql-1.2.1 lib/graphql/execution/typecast.rb
graphql-1.2.0 lib/graphql/execution/typecast.rb
graphql-1.1.0 lib/graphql/execution/typecast.rb
graphql-1.0.0 lib/graphql/execution/typecast.rb
graphql-0.19.4 lib/graphql/execution/typecast.rb
graphql-0.19.3 lib/graphql/execution/typecast.rb
graphql-0.19.2 lib/graphql/execution/typecast.rb
graphql-0.19.1 lib/graphql/execution/typecast.rb
graphql-0.19.0 lib/graphql/execution/typecast.rb
graphql-0.18.15 lib/graphql/execution/typecast.rb
graphql-0.18.14 lib/graphql/execution/typecast.rb
graphql-0.18.13 lib/graphql/execution/typecast.rb
graphql-0.18.12 lib/graphql/execution/typecast.rb
graphql-0.18.11 lib/graphql/execution/typecast.rb
graphql-0.18.10 lib/graphql/execution/typecast.rb