Sha256: 0f3cd42c1f0b7293fe42543b21cd3dd376a7857c6a139fd500adcbb4007e309b

Contents?: true

Size: 1.69 KB

Versions: 12

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

module GraphQL
  class Schema
    # Represents a non null type in the schema.
    # Wraps a {Schema::Member} when it is required.
    # @see {Schema::Member::TypeSystemHelpers#to_non_null_type}
    class NonNull < GraphQL::Schema::Wrapper
      include Schema::Member::ValidatesInput

      # @return [GraphQL::TypeKinds::NON_NULL]
      def kind
        GraphQL::TypeKinds::NON_NULL
      end

      # @return [true]
      def non_null?
        true
      end

      # @return [Boolean] True if this type wraps a list type
      def list?
        @of_type.list?
      end

      def to_type_signature
        "#{@of_type.to_type_signature}!"
      end

      def inspect
        "#<#{self.class.name} @of_type=#{@of_type.inspect}>"
      end

      def validate_input(value, ctx)
        if value.nil?
          result = GraphQL::Query::InputValidationResult.new
          result.add_problem("Expected value to not be null")
          result
        else
          of_type.validate_input(value, ctx)
        end
      end

      # This is for introspection, where it's expected the name will be `null`
      def graphql_name
        nil
      end

      def coerce_input(value, ctx)
        # `.validate_input` above is used for variables, but this method is used for arguments
        if value.nil?
          raise GraphQL::ExecutionError, "`null` is not a valid input for `#{to_type_signature}`, please provide a value for this argument."
        end
        of_type.coerce_input(value, ctx)
      end

      def coerce_result(value, ctx)
        of_type.coerce_result(value, ctx)
      end

      # This is for implementing introspection
      def description
        nil
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
graphql-2.0.12 lib/graphql/schema/non_null.rb
graphql-2.0.11 lib/graphql/schema/non_null.rb
graphql-2.0.9 lib/graphql/schema/non_null.rb
graphql-2.0.8 lib/graphql/schema/non_null.rb
graphql-2.0.7 lib/graphql/schema/non_null.rb
graphql-2.0.6 lib/graphql/schema/non_null.rb
graphql-2.0.5 lib/graphql/schema/non_null.rb
graphql-2.0.4 lib/graphql/schema/non_null.rb
graphql-2.0.3 lib/graphql/schema/non_null.rb
graphql-2.0.2 lib/graphql/schema/non_null.rb
graphql-2.0.1 lib/graphql/schema/non_null.rb
graphql-2.0.0 lib/graphql/schema/non_null.rb