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: ModifiesAnotherType
Instance Attribute Summary collapse
-
#description ⇒ String?
A description for this type.
-
#name ⇒ String
The name of this type, must be unique within a Schema.
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 ⇒ GraphQL::ObjectType
The default connection type for this object type.
-
#define_connection(**kwargs, &block) ⇒ GraphQL::ObjectType
Define a custom connection type for this object type.
-
#define_edge(**kwargs, &block) ⇒ GraphQL::ObjectType
Define a custom edge type for this object type.
-
#edge_type ⇒ GraphQL::ObjectType
The default edge type for this object type.
-
#get_field(name) ⇒ GraphQL::Field?
Types with fields may override this.
- #initialize_copy(other) ⇒ Object
-
#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, warden) ⇒ Boolean
- #validate_input(value, warden) ⇒ Object
Methods included from Define::InstanceDefinable
Methods included from Define::NonNullWithBang
Instance Attribute Details
#description ⇒ String?
Returns a description for this type.
25 26 27 |
# File 'lib/graphql/base_type.rb', line 25 def description @description end |
#name ⇒ String
Returns the name of this type, must be unique within a Schema.
22 23 24 |
# File 'lib/graphql/base_type.rb', line 22 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
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/graphql/base_type.rb', line 99 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).
29 30 31 32 33 34 35 |
# File 'lib/graphql/base_type.rb', line 29 def ==(other) if other.is_a?(GraphQL::BaseType) self.to_s == other.to_s else super end end |
#coerce_input(value) ⇒ Object
84 85 86 87 |
# File 'lib/graphql/base_type.rb', line 84 def coerce_input(value) return nil if value.nil? coerce_non_null_input(value) end |
#connection_type ⇒ GraphQL::ObjectType
Returns The default connection type for this object type.
113 114 115 |
# File 'lib/graphql/base_type.rb', line 113 def connection_type @connection_type ||= define_connection end |
#define_connection(**kwargs, &block) ⇒ GraphQL::ObjectType
Define a custom connection type for this object type
119 120 121 |
# File 'lib/graphql/base_type.rb', line 119 def define_connection(**kwargs, &block) GraphQL::Relay::ConnectionType.create_type(self, **kwargs, &block) end |
#define_edge(**kwargs, &block) ⇒ GraphQL::ObjectType
Define a custom edge type for this object type
130 131 132 |
# File 'lib/graphql/base_type.rb', line 130 def define_edge(**kwargs, &block) GraphQL::Relay::EdgeType.create_type(self, **kwargs, &block) end |
#edge_type ⇒ GraphQL::ObjectType
Returns The default edge type for this object type.
124 125 126 |
# File 'lib/graphql/base_type.rb', line 124 def edge_type @edge_type ||= define_edge end |
#get_field(name) ⇒ GraphQL::Field?
Types with fields may override this
92 93 94 |
# File 'lib/graphql/base_type.rb', line 92 def get_field(name) nil end |
#initialize_copy(other) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/graphql/base_type.rb', line 14 def initialize_copy(other) super # Reset these derived defaults @connection_type = nil @edge_type = 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)
61 62 63 |
# File 'lib/graphql/base_type.rb', line 61 def resolve_type(value) self end |
#to_list_type ⇒ GraphQL::ListType
Returns a list version of this type.
49 50 51 |
# File 'lib/graphql/base_type.rb', line 49 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.
44 45 46 |
# File 'lib/graphql/base_type.rb', line 44 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
66 67 68 |
# File 'lib/graphql/base_type.rb', line 66 def to_s name end |
#unwrap ⇒ Object
If this type is modifying an underlying type,
return the underlying type. (Otherwise, return self
.)
39 40 41 |
# File 'lib/graphql/base_type.rb', line 39 def unwrap self end |
#valid_input?(value, warden) ⇒ Boolean
72 73 74 |
# File 'lib/graphql/base_type.rb', line 72 def valid_input?(value, warden) validate_input(value, warden).valid? end |
#validate_input(value, warden) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/graphql/base_type.rb', line 76 def validate_input(value, warden) if value.nil? GraphQL::Query::InputValidationResult.new else validate_non_null_input(value, warden) end end |