Class: GraphQL::Field
- Inherits:
-
Object
- Object
- GraphQL::Field
- Includes:
- Define::InstanceDefinable
- Defined in:
- lib/graphql/field.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.
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`.
-
#deprecation_reason ⇒ Object
Returns the value of attribute deprecation_reason.
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ String
The name of this field on its ObjectType (or InterfaceType).
-
#property ⇒ Object
Returns the value of attribute property.
-
#resolve_proc ⇒ Object
readonly
Returns the value of attribute resolve_proc.
Instance Method Summary collapse
-
#initialize ⇒ Field
constructor
A new instance of Field.
-
#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
Constructor Details
#initialize ⇒ Field
Returns a new instance of Field.
75 76 77 78 79 |
# File 'lib/graphql/field.rb', line 75 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.
70 71 72 |
# File 'lib/graphql/field.rb', line 70 def arguments @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`.
73 74 75 |
# File 'lib/graphql/field.rb', line 73 def complexity @complexity end |
#deprecation_reason ⇒ Object
Returns the value of attribute deprecation_reason.
62 63 64 |
# File 'lib/graphql/field.rb', line 62 def deprecation_reason @deprecation_reason end |
#description ⇒ Object
Returns the value of attribute description.
62 63 64 |
# File 'lib/graphql/field.rb', line 62 def description @description end |
#name ⇒ String
Returns The name of this field on its ObjectType (or InterfaceType).
67 68 69 |
# File 'lib/graphql/field.rb', line 67 def name @name end |
#property ⇒ Object
Returns the value of attribute property.
62 63 64 |
# File 'lib/graphql/field.rb', line 62 def property @property end |
#resolve_proc ⇒ Object (readonly)
Returns the value of attribute resolve_proc.
64 65 66 |
# File 'lib/graphql/field.rb', line 64 def resolve_proc @resolve_proc end |
Instance Method Details
#resolve(object, arguments, context) ⇒ Object
Get a value for this field
88 89 90 |
# File 'lib/graphql/field.rb', line 88 def resolve(object, arguments, context) @resolve_proc.call(object, arguments, context) end |
#resolve=(resolve_proc) ⇒ Object
92 93 94 |
# File 'lib/graphql/field.rb', line 92 def resolve=(resolve_proc) @resolve_proc = resolve_proc || build_default_resolver end |
#to_s ⇒ Object
118 119 120 |
# File 'lib/graphql/field.rb', line 118 def to_s "<Field: #{name || "not-named"}>" end |
#type ⇒ Object
Get the return type for this field.
102 103 104 |
# File 'lib/graphql/field.rb', line 102 def type @clean_type ||= GraphQL::BaseType.(@dirty_type) end |
#type=(new_return_type) ⇒ Object
96 97 98 99 |
# File 'lib/graphql/field.rb', line 96 def type=(new_return_type) @clean_type = nil @dirty_type = new_return_type end |