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
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
-
#connection_type ⇒ Object
Get the default connection type for this object type.
-
#define_connection(**kwargs, &block) ⇒ Object
Define a custom connection type for this object type.
-
#define_edge(**kwargs, &block) ⇒ Object
Define a custom edge type for this object type.
-
#edge_type ⇒ Object
Get the default edge type for this object type.
-
#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
#definition_proc=, included, #metadata
Methods included from Define::NonNullWithBang
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
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/graphql/base_type.rb', line 107 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).
15 16 17 18 19 20 21 |
# File 'lib/graphql/base_type.rb', line 15 def ==(other) if other.is_a?(GraphQL::BaseType) self.to_s == other.to_s else super end end |
#coerce_input(value) ⇒ Object
92 93 94 95 |
# File 'lib/graphql/base_type.rb', line 92 def coerce_input(value) return nil if value.nil? coerce_non_null_input(value) end |
#connection_type ⇒ Object
Get the default connection type for this object type
121 122 123 |
# File 'lib/graphql/base_type.rb', line 121 def connection_type @connection_type ||= define_connection end |
#define_connection(**kwargs, &block) ⇒ Object
Define a custom connection type for this object type
126 127 128 |
# File 'lib/graphql/base_type.rb', line 126 def define_connection(**kwargs, &block) GraphQL::Relay::ConnectionType.create_type(self, **kwargs, &block) end |
#define_edge(**kwargs, &block) ⇒ Object
Define a custom edge type for this object type
136 137 138 |
# File 'lib/graphql/base_type.rb', line 136 def define_edge(**kwargs, &block) GraphQL::Relay::EdgeType.create_type(self, **kwargs, &block) end |
#edge_type ⇒ Object
Get the default edge type for this object type
131 132 133 |
# File 'lib/graphql/base_type.rb', line 131 def edge_type @edge_type ||= define_edge end |
#get_field(name) ⇒ GraphQL::Field?
Types with fields may override this
100 101 102 |
# File 'lib/graphql/base_type.rb', line 100 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)
47 48 49 |
# File 'lib/graphql/base_type.rb', line 47 def resolve_type(value) self end |
#to_list_type ⇒ GraphQL::ListType
Returns a list version of this type.
35 36 37 |
# File 'lib/graphql/base_type.rb', line 35 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.
30 31 32 |
# File 'lib/graphql/base_type.rb', line 30 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
77 78 79 |
# File 'lib/graphql/base_type.rb', line 77 def to_s name end |
#unwrap ⇒ Object
If this type is modifying an underlying type, return the underlying type. (Otherwise, return ‘self`.)
25 26 27 |
# File 'lib/graphql/base_type.rb', line 25 def unwrap self end |
#valid_input?(value) ⇒ Boolean
83 84 85 |
# File 'lib/graphql/base_type.rb', line 83 def valid_input?(value) validate_input(value).valid? end |
#validate_input(value) ⇒ Object
87 88 89 90 |
# File 'lib/graphql/base_type.rb', line 87 def validate_input(value) return GraphQL::Query::InputValidationResult.new if value.nil? validate_non_null_input(value) end |