Sha256: ef01d4401f3feaeb597ef311881bcc39b7d09d9652e662077a278e98bc7ec349

Contents?: true

Size: 751 Bytes

Versions: 3

Compression:

Stored size: 751 Bytes

Contents

# A non-null type wraps another type.
#
# Get the underlying type with {#unwrap}
class GraphQL::NonNullType < GraphQL::BaseType
  include GraphQL::BaseType::ModifiesAnotherType

  attr_reader :of_type
  def initialize(of_type:)
    @of_type = of_type
  end

  def name
    "Non-Null"
  end

  def valid_input?(value)
    validate_input(value).valid?
  end

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

  def coerce_input(value)
    of_type.coerce_input(value)
  end

  def kind
    GraphQL::TypeKinds::NON_NULL
  end

  def to_s
    "#{of_type.to_s}!"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
graphql-0.12.1 lib/graphql/non_null_type.rb
graphql-0.12.0 lib/graphql/non_null_type.rb
graphql-0.11.1 lib/graphql/non_null_type.rb