Class: Rails::GraphQL::Type
- Inherits:
-
Object
- Object
- Rails::GraphQL::Type
- Extended by:
- ActiveSupport::Autoload, Helpers::Registerable, Helpers::WithDirectives, Helpers::WithGlobalID
- Defined in:
- lib/rails/graphql/type.rb,
lib/rails/graphql/type/enum.rb,
lib/rails/graphql/type/input.rb,
lib/rails/graphql/type/union.rb,
lib/rails/graphql/type/object.rb,
lib/rails/graphql/type/scalar.rb,
lib/rails/graphql/type/creator.rb,
lib/rails/graphql/type/interface.rb,
lib/rails/graphql/type/scalar/id_scalar.rb,
lib/rails/graphql/type/scalar/any_scalar.rb,
lib/rails/graphql/type/scalar/int_scalar.rb,
lib/rails/graphql/type/object/type_object.rb,
lib/rails/graphql/type/scalar/date_scalar.rb,
lib/rails/graphql/type/scalar/json_scalar.rb,
lib/rails/graphql/type/scalar/time_scalar.rb,
lib/rails/graphql/type/enum/type_kind_enum.rb,
lib/rails/graphql/type/object/field_object.rb,
lib/rails/graphql/type/scalar/float_scalar.rb,
lib/rails/graphql/type/object/schema_object.rb,
lib/rails/graphql/type/scalar/bigint_scalar.rb,
lib/rails/graphql/type/scalar/binary_scalar.rb,
lib/rails/graphql/type/scalar/string_scalar.rb,
lib/rails/graphql/type/scalar/boolean_scalar.rb,
lib/rails/graphql/type/scalar/decimal_scalar.rb,
lib/rails/graphql/type/object/directive_object.rb,
lib/rails/graphql/type/scalar/date_time_scalar.rb,
lib/rails/graphql/type/object/enum_value_object.rb,
lib/rails/graphql/type/object/input_value_object.rb,
lib/rails/graphql/type/enum/directive_location_enum.rb
Overview
GraphQL Type
This is the most pure object from GraphQL. Anything that a schema can define will be an extension of this class See: spec.graphql.org/June2018/#sec-Types
Defined Under Namespace
Classes: Creator, Enum, Input, Interface, Object, Scalar, Union
Constant Summary collapse
- KINDS =
A direct representation of the spec types
%w[Scalar Object Interface Union Enum Input].freeze
Class Method Summary collapse
-
.=~(other) ⇒ Object
(also: of_type?)
Check if the other type is equivalent.
-
.base_type ⇒ Object
Returns the base type of the class.
-
.create!(from, name, superclass = nil, **xargs, &configure) ⇒ Object
Dynamically create a new type using the Creator.
-
.decorate(value) ⇒ Object
A little helper to instantiate the type if necessary.
-
.find_by_gid(gid) ⇒ Object
Return the type object, instantiate if it has params.
-
.gid_base_class ⇒ Object
This cannot be defined using alias because the
base_type
method is overridden by all children classes. -
.input_type? ⇒ Boolean
Defines if the current type is a valid input type.
-
.kind ⇒ Object
Return the base type in a symbolized way.
-
.kind_enum ⇒ Object
Return the specific value for the __TypeKind of this class.
-
.leaf_type? ⇒ Boolean
Defines if the current type is a leaf output type.
-
.operational? ⇒ Boolean
Defines if the object is a source of operations, which is only used for fake base types like
_Query
and_Mutation
. -
.output_type? ⇒ Boolean
Defines if the current type is a valid output type.
-
.to_gql_backtrace ⇒ Object
Similar to inspect, but summarized.
Methods included from Helpers::WithDirectives
all_directive_events, all_directive_listeners, directive_events?, directive_listeners?, extended, included, initialize_copy, use, using?, validate!
Methods included from Helpers::WithGlobalID
Methods included from Helpers::Registerable
aliases, extended, inherited, register!, registered?
Class Method Details
.=~(other) ⇒ Object Also known as: of_type?
Check if the other type is equivalent
49 50 51 |
# File 'lib/rails/graphql/type.rb', line 49 def =~(other) (other.is_a?(Module) ? other : other.class) <= self end |
.base_type ⇒ Object
Returns the base type of the class. It will be one of the classes defined on Type::KINDS
38 39 40 |
# File 'lib/rails/graphql/type.rb', line 38 def base_type nil end |
.create!(from, name, superclass = nil, **xargs, &configure) ⇒ Object
Dynamically create a new type using the Creator
104 105 106 |
# File 'lib/rails/graphql/type.rb', line 104 def create!(from, name, superclass = nil, **xargs, &configure) Creator.create!(from, name, superclass || self, **xargs, &configure) end |
.decorate(value) ⇒ Object
A little helper to instantiate the type if necessary
87 88 89 |
# File 'lib/rails/graphql/type.rb', line 87 def decorate(value) value end |
.find_by_gid(gid) ⇒ Object
Return the type object, instantiate if it has params
92 93 94 95 96 |
# File 'lib/rails/graphql/type.rb', line 92 def find_by_gid(gid) = { namespaces: gid.namespace.to_sym, base_class: :Type } klass = GraphQL.type_map.fetch!(gid.name, **) gid.instantiate? ? klass.build(**gid.params) : klass end |
.gid_base_class ⇒ Object
This cannot be defined using alias because the base_type
method is overridden by all children classes
44 45 46 |
# File 'lib/rails/graphql/type.rb', line 44 def gid_base_class base_type end |
.input_type? ⇒ Boolean
Defines if the current type is a valid input type
66 67 68 |
# File 'lib/rails/graphql/type.rb', line 66 def input_type? false end |
.kind ⇒ Object
Return the base type in a symbolized way
56 57 58 |
# File 'lib/rails/graphql/type.rb', line 56 def kind base_type.name.demodulize.underscore.to_sym end |
.kind_enum ⇒ Object
Return the specific value for the __TypeKind of this class
61 62 63 |
# File 'lib/rails/graphql/type.rb', line 61 def kind_enum kind.to_s.upcase end |
.leaf_type? ⇒ Boolean
Defines if the current type is a leaf output type
76 77 78 |
# File 'lib/rails/graphql/type.rb', line 76 def leaf_type? false end |
.operational? ⇒ Boolean
Defines if the object is a source of operations, which is only used for fake base types like _Query
and _Mutation
82 83 84 |
# File 'lib/rails/graphql/type.rb', line 82 def operational? false end |
.output_type? ⇒ Boolean
Defines if the current type is a valid output type
71 72 73 |
# File 'lib/rails/graphql/type.rb', line 71 def output_type? false end |
.to_gql_backtrace ⇒ Object
Similar to inspect, but summarized
99 100 101 |
# File 'lib/rails/graphql/type.rb', line 99 def to_gql_backtrace +"#<GraphQL::#{base_type.name.demodulize} #{gql_name}>" end |