Class: GraphQL::Field
- Inherits:
-
Object
- Object
- GraphQL::Field
- Includes:
- Define::InstanceDefinable
- Defined in:
- lib/graphql/field.rb,
lib/graphql/field/resolve.rb
Overview
Fields belong to ObjectTypes and InterfaceTypes.
They’re usually created with the ‘field` helper. If you create it by hand, make sure #name is a String.
Defined Under Namespace
Modules: Resolve
Instance Attribute Summary collapse
-
#arguments ⇒ Hash<String => GraphQL::Argument>
Map String argument names to their Argument implementations.
-
#complexity ⇒ Numeric, Proc
The complexity for this field (default: 1), as a constant or a proc like ‘-> (query_ctx, args, child_complexity) { } # Numeric`.
-
#name ⇒ String
The name of this field on its ObjectType (or InterfaceType).
-
#resolve_proc ⇒ Object
readonly
Returns the value of attribute resolve_proc.
Instance Method Summary collapse
- #hash_key=(new_hash_key) ⇒ Object
-
#initialize ⇒ Field
constructor
A new instance of Field.
- #property=(new_property) ⇒ Object
-
#resolve(object, arguments, context) ⇒ Object
Get a value for this field.
- #resolve=(resolve_proc) ⇒ Object
- #to_s ⇒ Object
-
#type ⇒ Object
Get the return type for this field.
- #type=(new_return_type) ⇒ Object
Methods included from Define::InstanceDefinable
#definition_proc=, included, #metadata
Constructor Details
#initialize ⇒ Field
Returns a new instance of Field.
92 93 94 95 96 |
# File 'lib/graphql/field.rb', line 92 def initialize @complexity = 1 @arguments = {} @resolve_proc = build_default_resolver end |
Instance Attribute Details
#arguments ⇒ Hash<String => GraphQL::Argument>
Returns Map String argument names to their Argument implementations.
77 78 79 80 |
# File 'lib/graphql/field.rb', line 77 def arguments ensure_defined @arguments end |
#complexity ⇒ Numeric, Proc
Returns The complexity for this field (default: 1), as a constant or a proc like ‘-> (query_ctx, args, child_complexity) { } # Numeric`.
85 86 87 88 |
# File 'lib/graphql/field.rb', line 85 def complexity ensure_defined @complexity end |
#name ⇒ String
Returns The name of this field on its ObjectType (or InterfaceType).
69 70 71 72 |
# File 'lib/graphql/field.rb', line 69 def name ensure_defined @name end |
#resolve_proc ⇒ Object (readonly)
Returns the value of attribute resolve_proc.
66 67 68 |
# File 'lib/graphql/field.rb', line 66 def resolve_proc @resolve_proc end |
Instance Method Details
#hash_key=(new_hash_key) ⇒ Object
150 151 152 153 154 |
# File 'lib/graphql/field.rb', line 150 def hash_key=(new_hash_key) ensure_defined @hash_key = new_hash_key self.resolve = nil # reset resolve proc end |
#property=(new_property) ⇒ Object
143 144 145 146 147 |
# File 'lib/graphql/field.rb', line 143 def property=(new_property) ensure_defined @property = new_property self.resolve = nil # reset resolve proc end |
#resolve(object, arguments, context) ⇒ Object
Get a value for this field
105 106 107 108 |
# File 'lib/graphql/field.rb', line 105 def resolve(object, arguments, context) ensure_defined resolve_proc.call(object, arguments, context) end |
#resolve=(resolve_proc) ⇒ Object
110 111 112 113 |
# File 'lib/graphql/field.rb', line 110 def resolve=(resolve_proc) ensure_defined @resolve_proc = resolve_proc || build_default_resolver end |
#to_s ⇒ Object
156 157 158 |
# File 'lib/graphql/field.rb', line 156 def to_s "<Field name:#{name || "not-named"} desc:#{description} resolve:#{resolve_proc}>" end |
#type ⇒ Object
Get the return type for this field.
122 123 124 125 126 127 |
# File 'lib/graphql/field.rb', line 122 def type @clean_type ||= begin ensure_defined GraphQL::BaseType.(@dirty_type) end end |
#type=(new_return_type) ⇒ Object
115 116 117 118 119 |
# File 'lib/graphql/field.rb', line 115 def type=(new_return_type) ensure_defined @clean_type = nil @dirty_type = new_return_type end |