Class: GraphQL::NonNullType
- 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 raised.)
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
Instance Method Summary collapse
- #coerce_input(value) ⇒ Object
- #coerce_result(value) ⇒ Object
-
#initialize(of_type:) ⇒ NonNullType
constructor
A new instance of NonNullType.
- #kind ⇒ Object
- #to_s ⇒ Object
- #valid_input?(value, warden) ⇒ Boolean
- #validate_input(value, warden) ⇒ Object
Methods included from BaseType::ModifiesAnotherType
Methods inherited from BaseType
#==, #connection_type, #define_connection, #define_edge, #edge_type, #get_field, resolve_related_type, #resolve_type, #to_list_type, #to_non_null_type, #unwrap
Methods included from Define::InstanceDefinable
Methods included from Define::NonNullWithBang
Constructor Details
#initialize(of_type:) ⇒ NonNullType
Returns a new instance of NonNullType.
34 35 36 |
# File 'lib/graphql/non_null_type.rb', line 34 def initialize(of_type:) @of_type = of_type end |
Instance Attribute Details
#of_type ⇒ Object (readonly)
Returns the value of attribute of_type.
33 34 35 |
# File 'lib/graphql/non_null_type.rb', line 33 def of_type @of_type end |
Instance Method Details
#coerce_input(value) ⇒ Object
52 53 54 |
# File 'lib/graphql/non_null_type.rb', line 52 def coerce_input(value) of_type.coerce_input(value) end |
#coerce_result(value) ⇒ Object
56 57 58 |
# File 'lib/graphql/non_null_type.rb', line 56 def coerce_result(value) of_type.coerce_result(value) end |
#kind ⇒ Object
60 61 62 |
# File 'lib/graphql/non_null_type.rb', line 60 def kind GraphQL::TypeKinds::NON_NULL end |
#to_s ⇒ Object
64 65 66 |
# File 'lib/graphql/non_null_type.rb', line 64 def to_s "#{of_type.to_s}!" end |
#valid_input?(value, warden) ⇒ Boolean
38 39 40 |
# File 'lib/graphql/non_null_type.rb', line 38 def valid_input?(value, warden) validate_input(value, warden).valid? end |
#validate_input(value, warden) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/graphql/non_null_type.rb', line 42 def validate_input(value, warden) if value.nil? result = GraphQL::Query::InputValidationResult.new result.add_problem("Expected value to not be null") result else of_type.validate_input(value, warden) end end |