Sha256: e8edc23d526a751df3f1c09613b16d1e90eab8d02cce84988568c689f394dbc0

Contents?: true

Size: 1.57 KB

Versions: 168

Compression:

Stored size: 1.57 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 union
            # if the union includes that type
            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

168 entries across 168 versions & 2 rubygems

Version Path
graphql-1.13.23 lib/graphql/execution/typecast.rb
graphql-1.13.22 lib/graphql/execution/typecast.rb
graphql-1.13.21 lib/graphql/execution/typecast.rb
graphql-1.13.20 lib/graphql/execution/typecast.rb
graphql-1.13.19 lib/graphql/execution/typecast.rb
graphql-1.13.18 lib/graphql/execution/typecast.rb
graphql-1.13.17 lib/graphql/execution/typecast.rb
graphql-1.13.16 lib/graphql/execution/typecast.rb
graphql-1.13.15 lib/graphql/execution/typecast.rb
graphql-1.13.14 lib/graphql/execution/typecast.rb
graphql-1.13.13 lib/graphql/execution/typecast.rb
graphql_cody-1.13.0 lib/graphql/execution/typecast.rb
graphql-1.13.12 lib/graphql/execution/typecast.rb
graphql-1.13.11 lib/graphql/execution/typecast.rb
graphql-1.13.10 lib/graphql/execution/typecast.rb
graphql-1.13.9 lib/graphql/execution/typecast.rb
graphql-1.12.24 lib/graphql/execution/typecast.rb
graphql-1.13.8 lib/graphql/execution/typecast.rb
graphql-1.13.7 lib/graphql/execution/typecast.rb
graphql-1.13.6 lib/graphql/execution/typecast.rb