class GraphQL::NonNullType

A non-null type modifies another type.

Non-null types can be created with `!` (`InnerType!`) or {BaseType#to_non_null_type} (`InnerType.to_non_null_type`)

For return types, it says that the returned value will always be present.

@example A field which always returns an error

field :items, !ItemType
# or
field :items, ItemType.to_non_null_type

(If the application fails to return a value, {InvalidNullError} will be passed to {Schema#type_error}.)

For input types, it says that the incoming value must be provided by the query.

@example A field which requires a string input

field :newNames do
  # ...
  argument :values, !types.String
  # or
  argument :values, types.String.to_non_null_type
end

(If a value isn't provided, {Query::VariableValidationError} will be raised).

Given a non-null type, you can always get the underlying type with {#unwrap}.

Attributes

of_type[R]

Public Class Methods

new(of_type:) click to toggle source
Calls superclass method GraphQL::BaseType::new
# File lib/graphql/non_null_type.rb, line 36
def initialize(of_type:)
  super()
  @of_type = of_type
end

Public Instance Methods

inspect()
Alias for: to_s
kind() click to toggle source
# File lib/graphql/non_null_type.rb, line 57
def kind
  GraphQL::TypeKinds::NON_NULL
end
non_null?() click to toggle source
# File lib/graphql/non_null_type.rb, line 67
def non_null?
  true
end
to_s() click to toggle source
# File lib/graphql/non_null_type.rb, line 61
def to_s
  "#{of_type.to_s}!"
end
Also aliased as: inspect, to_type_signature
to_type_signature()
Alias for: to_s
valid_input?(value, ctx) click to toggle source
# File lib/graphql/non_null_type.rb, line 41
def valid_input?(value, ctx)
  validate_input(value, ctx).valid?
end
validate_input(value, ctx) click to toggle source
# File lib/graphql/non_null_type.rb, line 45
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