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
- #default_relay ⇒ Object writeonly private
- #default_scalar ⇒ Object writeonly private
-
#description ⇒ String?
A description for this type.
- #introspection ⇒ Object writeonly private
-
#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.
-
#default_relay? ⇒ Boolean
Is this type a built-in Relay type? (
Node
,PageInfo
). -
#default_scalar? ⇒ Boolean
Is this type a built-in scalar type? (eg,
String
,Int
). -
#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 ⇒ BaseType
constructor
A new instance of BaseType.
- #initialize_copy(other) ⇒ Object
-
#introspection? ⇒ Boolean
Is this type a predefined introspection type?.
-
#resolve_type(value) ⇒ Object
Find out which possible type to use for
value
. -
#to_definition(schema, printer: nil, **args) ⇒ String
Return a GraphQL string for the type definition.
-
#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
Constructor Details
#initialize ⇒ BaseType
Returns a new instance of BaseType.
18 19 20 21 22 |
# File 'lib/graphql/base_type.rb', line 18 def initialize @introspection = false @default_scalar = false @default_relay = false end |
Instance Attribute Details
#default_relay=(value) ⇒ Object (writeonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 |
# File 'lib/graphql/base_type.rb', line 53 def default_relay=(value) @default_relay = value end |
#default_scalar=(value) ⇒ Object (writeonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 |
# File 'lib/graphql/base_type.rb', line 53 def default_scalar=(value) @default_scalar = value end |
#description ⇒ String?
Returns a description for this type.
35 36 37 |
# File 'lib/graphql/base_type.rb', line 35 def description @description end |
#introspection=(value) ⇒ Object (writeonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 |
# File 'lib/graphql/base_type.rb', line 53 def introspection=(value) @introspection = value end |
#name ⇒ String
Returns the name of this type, must be unique within a Schema.
32 33 34 |
# File 'lib/graphql/base_type.rb', line 32 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
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/graphql/base_type.rb', line 127 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).
57 58 59 60 61 62 63 |
# File 'lib/graphql/base_type.rb', line 57 def ==(other) if other.is_a?(GraphQL::BaseType) self.to_s == other.to_s else super end end |
#coerce_input(value) ⇒ Object
112 113 114 115 |
# File 'lib/graphql/base_type.rb', line 112 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.
141 142 143 |
# File 'lib/graphql/base_type.rb', line 141 def connection_type @connection_type ||= define_connection end |
#default_relay? ⇒ Boolean
Returns Is this type a built-in Relay type? (Node
, PageInfo
).
48 49 50 |
# File 'lib/graphql/base_type.rb', line 48 def default_relay? @default_relay end |
#default_scalar? ⇒ Boolean
Returns Is this type a built-in scalar type? (eg, String
, Int
).
43 44 45 |
# File 'lib/graphql/base_type.rb', line 43 def default_scalar? @default_scalar end |
#define_connection(**kwargs, &block) ⇒ GraphQL::ObjectType
Define a custom connection type for this object type
147 148 149 |
# File 'lib/graphql/base_type.rb', line 147 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
158 159 160 |
# File 'lib/graphql/base_type.rb', line 158 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.
152 153 154 |
# File 'lib/graphql/base_type.rb', line 152 def edge_type @edge_type ||= define_edge end |
#get_field(name) ⇒ GraphQL::Field?
Types with fields may override this
120 121 122 |
# File 'lib/graphql/base_type.rb', line 120 def get_field(name) nil end |
#initialize_copy(other) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/graphql/base_type.rb', line 24 def initialize_copy(other) super # Reset these derived defaults @connection_type = nil @edge_type = nil end |
#introspection? ⇒ Boolean
Returns Is this type a predefined introspection type?.
38 39 40 |
# File 'lib/graphql/base_type.rb', line 38 def introspection? @introspection 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)
89 90 91 |
# File 'lib/graphql/base_type.rb', line 89 def resolve_type(value) self end |
#to_definition(schema, printer: nil, **args) ⇒ String
Return a GraphQL string for the type definition
167 168 169 170 |
# File 'lib/graphql/base_type.rb', line 167 def to_definition(schema, printer: nil, **args) printer ||= GraphQL::Schema::Printer.new(schema, **args) printer.print_type(self) end |
#to_list_type ⇒ GraphQL::ListType
Returns a list version of this type.
77 78 79 |
# File 'lib/graphql/base_type.rb', line 77 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.
72 73 74 |
# File 'lib/graphql/base_type.rb', line 72 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
94 95 96 |
# File 'lib/graphql/base_type.rb', line 94 def to_s name end |
#unwrap ⇒ Object
If this type is modifying an underlying type,
return the underlying type. (Otherwise, return self
.)
67 68 69 |
# File 'lib/graphql/base_type.rb', line 67 def unwrap self end |
#valid_input?(value, warden) ⇒ Boolean
100 101 102 |
# File 'lib/graphql/base_type.rb', line 100 def valid_input?(value, warden) validate_input(value, warden).valid? end |
#validate_input(value, warden) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/graphql/base_type.rb', line 104 def validate_input(value, warden) if value.nil? GraphQL::Query::InputValidationResult.new else validate_non_null_input(value, warden) end end |