Sha256: 81843a441da1e1d0052445b13a0af2a14c87dead5ca85546f420fa11dbdda329

Contents?: true

Size: 1.47 KB

Versions: 57

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true
module GraphQL
  class Schema
    # @api private
    module TypeExpression
      # Fetch a type from a type map by its AST specification.
      # Return `nil` if not found.
      # @param type_owner [#get_type] A thing for looking up types by name
      # @param ast_node [GraphQL::Language::Nodes::AbstractNode]
      # @return [Class, GraphQL::Schema::NonNull, GraphQL::Schema:List]
      def self.build_type(type_owner, ast_node)
        case ast_node
        when GraphQL::Language::Nodes::TypeName
          type_owner.get_type(ast_node.name)
        when GraphQL::Language::Nodes::NonNullType
          ast_inner_type = ast_node.of_type
          inner_type = build_type(type_owner, ast_inner_type)
          wrap_type(inner_type, :to_non_null_type)
        when GraphQL::Language::Nodes::ListType
          ast_inner_type = ast_node.of_type
          inner_type = build_type(type_owner, ast_inner_type)
          wrap_type(inner_type, :to_list_type)
        else
          raise "Invariant: unexpected type from ast: #{ast_node.inspect}"
        end
      end

      class << self
        private

        def wrap_type(type, wrapper_method)
          if type.nil?
            nil
          elsif wrapper_method == :to_list_type || wrapper_method == :to_non_null_type
            type.public_send(wrapper_method)
          else
            raise ArgumentError, "Unexpected wrapper method: #{wrapper_method.inspect}"
          end
        end
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
graphql-1.11.12 lib/graphql/schema/type_expression.rb
graphql-1.11.11 lib/graphql/schema/type_expression.rb
graphql-1.12.25 lib/graphql/schema/type_expression.rb
graphql-1.12.24 lib/graphql/schema/type_expression.rb
graphql-1.12.23 lib/graphql/schema/type_expression.rb
graphql-1.12.22 lib/graphql/schema/type_expression.rb
graphql-1.12.21 lib/graphql/schema/type_expression.rb
graphql-1.12.20 lib/graphql/schema/type_expression.rb
graphql-1.12.19 lib/graphql/schema/type_expression.rb
graphql-1.11.10 lib/graphql/schema/type_expression.rb
graphql-1.12.18 lib/graphql/schema/type_expression.rb
graphql-1.11.9 lib/graphql/schema/type_expression.rb
graphql-1.12.17 lib/graphql/schema/type_expression.rb
graphql-1.12.16 lib/graphql/schema/type_expression.rb
graphql-1.12.15 lib/graphql/schema/type_expression.rb
graphql-1.12.14 lib/graphql/schema/type_expression.rb
graphql-1.12.13 lib/graphql/schema/type_expression.rb
graphql-1.12.12 lib/graphql/schema/type_expression.rb
graphql-1.12.11 lib/graphql/schema/type_expression.rb
graphql-1.12.10 lib/graphql/schema/type_expression.rb