Class: GraphQL::NonNullType
- Extended by:
- Forwardable
- Includes:
- BaseType::ModifiesAnotherType
- Defined in:
- lib/graphql/non_null_type.rb
Overview
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.
(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.
(If a value isn’t provided, Query::VariableValidationError will be raised).
Given a non-null type, you can always get the underlying type with BaseType::ModifiesAnotherType#unwrap.
Instance Attribute Summary collapse
-
#of_type ⇒ Object
readonly
Returns the value of attribute of_type.
Attributes inherited from BaseType
#ast_node, #default_relay, #default_scalar, #description, #introspection, #name
Instance Method Summary collapse
-
#initialize(of_type:) ⇒ NonNullType
constructor
A new instance of NonNullType.
-
#kind ⇒ Object
-
#non_null? ⇒ Boolean
-
#to_s ⇒ Object
(also: #inspect, #to_type_signature)
-
#valid_input?(value, ctx) ⇒ Boolean
-
#validate_input(value, ctx) ⇒ Object
Methods included from BaseType::ModifiesAnotherType
Methods inherited from BaseType
#==, #coerce_input, #coerce_isolated_input, #coerce_isolated_result, #coerce_result, #default_relay?, #default_scalar?, #get_field, #initialize_copy, #introspection?, #list?, resolve_related_type, #resolve_type, #to_definition, #to_list_type, #to_non_null_type, #unwrap, #valid_isolated_input?, #validate_isolated_input
Methods included from Relay::TypeExtensions
#connection_type, #define_connection, #define_edge, #edge_type
Methods included from Define::InstanceDefinable
#define, #initialize_copy, #metadata, #redefine
Methods included from Define::NonNullWithBang
Constructor Details
#initialize(of_type:) ⇒ NonNullType
Returns a new instance of NonNullType
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/graphql/non_null_type.rb', line 39 def initialize(of_type:) if of_type.is_a?(GraphQL::NonNullType) raise( DoubleNonNullTypeError, "You tried to add a non-null constraint twice (!! instead of !)" ) end super() @of_type = of_type end |
Instance Attribute Details
#of_type ⇒ Object (readonly)
Returns the value of attribute of_type
38 39 40 |
# File 'lib/graphql/non_null_type.rb', line 38 def of_type @of_type end |
Instance Method Details
#kind ⇒ Object
67 68 69 |
# File 'lib/graphql/non_null_type.rb', line 67 def kind GraphQL::TypeKinds::NON_NULL end |
#non_null? ⇒ Boolean
77 78 79 |
# File 'lib/graphql/non_null_type.rb', line 77 def non_null? true end |
#to_s ⇒ Object Also known as: inspect, to_type_signature
71 72 73 |
# File 'lib/graphql/non_null_type.rb', line 71 def to_s "#{of_type.to_s}!" end |
#valid_input?(value, ctx) ⇒ Boolean
51 52 53 |
# File 'lib/graphql/non_null_type.rb', line 51 def valid_input?(value, ctx) validate_input(value, ctx).valid? end |
#validate_input(value, ctx) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/graphql/non_null_type.rb', line 55 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 |