Class: GraphQL::BaseType
- Inherits:
-
Object
- Object
- GraphQL::BaseType
- Includes:
- Define::InstanceDefinable, Define::NonNullWithBang
- 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 Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
-
.resolve_related_type(type_arg) ⇒ GraphQL::BaseType
During schema definition, types can be defined inside procs or as strings.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Are these types equivalent? (incl. non-null, list).
- #coerce_input(value) ⇒ Object
-
#get_field(name) ⇒ GraphQL::Field?
Types with fields may override this.
-
#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.
- #valid_input?(value) ⇒ Boolean
- #validate_input(value) ⇒ Object
Methods included from Define::InstanceDefinable
Methods included from Define::NonNullWithBang
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/graphql/base_type.rb', line 6 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/graphql/base_type.rb', line 6 def name @name end |
Class Method Details
.resolve_related_type(type_arg) ⇒ GraphQL::BaseType
During schema definition, types can be defined inside procs or as strings. This function converts it to a type instance
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/graphql/base_type.rb', line 102 def self.(type_arg) case type_arg when Proc # lazy-eval it type_arg.call when String # Get a constant by this name Object.const_get(type_arg) else type_arg end end |
Instance Method Details
#==(other) ⇒ Boolean
Returns are these types equivalent? (incl. non-null, list).
11 12 13 14 15 16 17 |
# File 'lib/graphql/base_type.rb', line 11 def ==(other) if other.is_a?(GraphQL::BaseType) self.to_s == other.to_s else super end end |
#coerce_input(value) ⇒ Object
87 88 89 90 |
# File 'lib/graphql/base_type.rb', line 87 def coerce_input(value) return nil if value.nil? coerce_non_null_input(value) end |
#get_field(name) ⇒ GraphQL::Field?
Types with fields may override this
95 96 97 |
# File 'lib/graphql/base_type.rb', line 95 def get_field(name) nil 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)
43 44 45 |
# File 'lib/graphql/base_type.rb', line 43 def resolve_type(value) self end |
#to_list_type ⇒ GraphQL::ListType
Returns a list version of this type.
31 32 33 |
# File 'lib/graphql/base_type.rb', line 31 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.
26 27 28 |
# File 'lib/graphql/base_type.rb', line 26 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
72 73 74 |
# File 'lib/graphql/base_type.rb', line 72 def to_s name end |
#unwrap ⇒ Object
If this type is modifying an underlying type, return the underlying type. (Otherwise, return ‘self`.)
21 22 23 |
# File 'lib/graphql/base_type.rb', line 21 def unwrap self end |
#valid_input?(value) ⇒ Boolean
78 79 80 |
# File 'lib/graphql/base_type.rb', line 78 def valid_input?(value) validate_input(value).valid? end |
#validate_input(value) ⇒ Object
82 83 84 85 |
# File 'lib/graphql/base_type.rb', line 82 def validate_input(value) return GraphQL::Query::InputValidationResult.new if value.nil? validate_non_null_input(value) end |