Class: GraphQL::BaseType
- Inherits:
-
Object
- Object
- GraphQL::BaseType
- Defined in:
- lib/graphql/base_type.rb
Overview
The parent for all type classes.
Direct Known Subclasses
EnumType, InputObjectType, InterfaceType, ListType, NonNullType, ObjectType, ScalarType, UnionType
Defined Under Namespace
Modules: HasPossibleTypes, ModifiesAnotherType
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Are these types equivalent? (incl. non-null, list).
-
#coerce_input!(input_value) ⇒ Object
Coerce ‘input_value` according to this type’s ‘coerce` method.
-
#resolve_type(value) ⇒ Object
Find out which possible type to use for ‘value`.
-
#to_list_type ⇒ GraphQL::ListType
A list version of this type.
-
#to_non_null_type ⇒ GraphQL::NonNullType
A non-null version of this type.
-
#to_s ⇒ Object
(also: #inspect)
Print the human-readable name of this type using the query-string naming pattern.
-
#unwrap ⇒ Object
If this type is modifying an underlying type, return the underlying type.
Methods included from DefinitionHelpers::DefinedByConfig
Methods included from DefinitionHelpers::NonNullWithBang
Instance Method Details
#==(other) ⇒ Boolean
Returns are these types equivalent? (incl. non-null, list).
9 10 11 12 13 14 15 |
# File 'lib/graphql/base_type.rb', line 9 def ==(other) if other.is_a?(GraphQL::BaseType) self.to_s == other.to_s else super end end |
#coerce_input!(input_value) ⇒ Object
Coerce ‘input_value` according to this type’s ‘coerce` method. Raise an error if the value becomes nil.
83 84 85 86 87 88 89 90 91 |
# File 'lib/graphql/base_type.rb', line 83 def coerce_input!(input_value) coerced_value = coerce_input(input_value) if coerced_value.nil? raise GraphQL::ExecutionError.new("Couldn't coerce #{input_value.inspect} to #{self.unwrap.name}") end coerced_value end |
#resolve_type(value) ⇒ Object
Find out which possible type to use for ‘value`. Returns self if there are no possible types (ie, not Union or Interface)
41 42 43 |
# File 'lib/graphql/base_type.rb', line 41 def resolve_type(value) self end |
#to_list_type ⇒ GraphQL::ListType
Returns a list version of this type.
29 30 31 |
# File 'lib/graphql/base_type.rb', line 29 def to_list_type GraphQL::ListType.new(of_type: self) end |
#to_non_null_type ⇒ GraphQL::NonNullType
Returns a non-null version of this type.
24 25 26 |
# File 'lib/graphql/base_type.rb', line 24 def to_non_null_type GraphQL::NonNullType.new(of_type: self) end |
#to_s ⇒ Object Also known as: inspect
Print the human-readable name of this type using the query-string naming pattern
73 74 75 |
# File 'lib/graphql/base_type.rb', line 73 def to_s name end |
#unwrap ⇒ Object
If this type is modifying an underlying type, return the underlying type. (Otherwise, return ‘self`.)
19 20 21 |
# File 'lib/graphql/base_type.rb', line 19 def unwrap self end |