Sha256: 3c341bd5cea96eedb723db788e15d81276617d1072019b283b974087b69a6199

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true
module GraphQL
  module Execution
    # @api private
    module Typecast
      # @return [Boolean]
      def self.subtype?(parent_type, child_type)
        if parent_type == child_type
          # Equivalent types are subtypes
          true
        elsif child_type.is_a?(GraphQL::NonNullType)
          # A non-null type is a subtype of a nullable type
          # if its inner type is a subtype of that type
          if parent_type.is_a?(GraphQL::NonNullType)
            subtype?(parent_type.of_type, child_type.of_type)
          else
            subtype?(parent_type, child_type.of_type)
          end
        else
          case parent_type
          when GraphQL::InterfaceType
            # A type is a subtype of an interface
            # if it implements that interface
            case child_type
            when GraphQL::ObjectType
              child_type.interfaces.include?(parent_type)
            else
              false
            end
          when GraphQL::UnionType
            # A type is a subtype of that interface
            # if the union includes that interface
            parent_type.possible_types.include?(child_type)
          when GraphQL::ListType
            # A list type is a subtype of another list type
            # if its inner type is a subtype of the other inner type
            case child_type
            when GraphQL::ListType
              subtype?(parent_type.of_type, child_type.of_type)
            else
              false
            end
          else
            false
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
graphql-1.5.7.1 lib/graphql/execution/typecast.rb
graphql-1.5.7 lib/graphql/execution/typecast.rb
graphql-1.5.6 lib/graphql/execution/typecast.rb
graphql-1.5.5 lib/graphql/execution/typecast.rb
graphql-1.5.4 lib/graphql/execution/typecast.rb
graphql-1.5.3 lib/graphql/execution/typecast.rb