Class: GraphQL::Field
- Inherits:
 - 
      Object
      
        
- Object
 - GraphQL::Field
 
 
- Includes:
 - Define::InstanceDefinable
 
- Defined in:
 - lib/graphql/field.rb,
lib/graphql/field/resolve.rb 
Defined Under Namespace
Modules: DefaultLazyResolve, Resolve
Instance Attribute Summary collapse
- 
  
    
      #arguments  ⇒ Hash<String => GraphQL::Argument> 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Map String argument names to their Argument implementations.
 - 
  
    
      #arguments_class  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
 - 
  
    
      #ast_node  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
 - 
  
    
      #complexity  ⇒ Numeric, Proc 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The complexity for this field (default: 1), as a constant or a proc like
->(query_ctx, args, child_complexity) { } # Numeric. - 
  
    
      #connection  ⇒ Object 
    
    
  
  
  
  
    
    
      writeonly
    
  
  
  
  
  
  
    
 - 
  
    
      #connection_max_page_size  ⇒ nil, Integer 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
 - 
  
    
      #deprecation_reason  ⇒ String? 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The client-facing reason why this field is deprecated (if present, the field is deprecated).
 - 
  
    
      #description  ⇒ String? 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The client-facing description of this field.
 - 
  
    
      #edge_class  ⇒ nil, Class 
    
    
  
  
  
  
    
    
  
  
  
  
  private
  
    
 - 
  
    
      #function  ⇒ Object, GraphQL::Function 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The function used to derive this field.
 - 
  
    
      #hash_key  ⇒ Object? 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The key to access with
obj.[]to resolve this field (overrides #name if present). - 
  
    
      #introspection  ⇒ Object 
    
    
  
  
  
  
    
    
      writeonly
    
  
  
  
  
  
  
    
 - 
  
    
      #lazy_resolve_proc  ⇒ <#call(obj, args, ctx)> 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
A proc-like object which can be called trigger a lazy resolution.
 - 
  
    
      #mutation  ⇒ GraphQL::Relay::Mutation? 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The mutation this field was derived from, if it was derived from a mutation.
 - 
  
    
      #name  ⇒ String 
    
    
      (also: #graphql_name)
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The name of this field on its ObjectType (or InterfaceType).
 - 
  
    
      #property  ⇒ Symbol? 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The method to call on
objto return this field (overrides #name if present). - 
  
    
      #relay_node_field  ⇒ Boolean 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
True if this is the Relay find-by-id field.
 - 
  
    
      #relay_nodes_field  ⇒ Boolean 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
True if this is the Relay find-by-ids field.
 - 
  
    
      #resolve_proc  ⇒ <#call(obj, args, ctx)> 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
A proc-like object which can be called to return the field’s value.
 - 
  
    
      #subscription_scope  ⇒ nil, String 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Prefix for subscription names from this field.
 - 
  
    
      #trace  ⇒ Boolean 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
True if this field should be traced.
 
Instance Method Summary collapse
- 
  
    
      #connection?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #edges?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #initialize  ⇒ Field 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Field.
 - 
  
    
      #initialize_copy(other)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #introspection?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Is this field a predefined introspection field?.
 - 
  
    
      #lazy_resolve(obj, args, ctx)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
If #resolve returned an object which should be handled lazily, this method will be called later to force the object to return its value.
 - 
  
    
      #lazy_resolve=(new_lazy_resolve_proc)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Assign a new resolve proc to this field.
 - 
  
    
      #prepare_lazy(obj, args, ctx)  ⇒ GraphQL::Execution::Lazy 
    
    
  
  
  
  
  
  
  
  
  
    
Prepare a lazy value for this field.
 - 
  
    
      #resolve(object, arguments, context)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Get a value for this field.
 - 
  
    
      #resolve=(new_resolve_proc)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Provide a new callable for this field’s resolve function.
 - 
  
    
      #to_s  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #type  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Get the return type for this field.
 - 
  
    
      #type=(new_return_type)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #type_class  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
 
Methods included from Define::InstanceDefinable
Constructor Details
#initialize ⇒ Field
Returns a new instance of Field.
      104 105 106 107 108 109 110 111 112 113 114 115  | 
    
      # File 'lib/graphql/field.rb', line 104 def initialize @complexity = 1 @arguments = {} @resolve_proc = build_default_resolver @lazy_resolve_proc = DefaultLazyResolve @relay_node_field = false @connection = false @connection_max_page_size = nil @edge_class = nil @trace = nil @introspection = false end  | 
  
Instance Attribute Details
#arguments ⇒ Hash<String => GraphQL::Argument>
Returns Map String argument names to their Argument implementations.
      53 54 55  | 
    
      # File 'lib/graphql/field.rb', line 53 def arguments @arguments end  | 
  
#arguments_class ⇒ Object
      70 71 72  | 
    
      # File 'lib/graphql/field.rb', line 70 def arguments_class @arguments_class end  | 
  
#ast_node ⇒ Object
      81 82 83  | 
    
      # File 'lib/graphql/field.rb', line 81 def ast_node @ast_node 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.
      59 60 61  | 
    
      # File 'lib/graphql/field.rb', line 59 def complexity @complexity end  | 
  
#connection=(value) ⇒ Object (writeonly)
      72 73 74  | 
    
      # File 'lib/graphql/field.rb', line 72 def connection=(value) @connection = value end  | 
  
#connection_max_page_size ⇒ nil, Integer
      102 103 104  | 
    
      # File 'lib/graphql/field.rb', line 102 def connection_max_page_size @connection_max_page_size end  | 
  
#deprecation_reason ⇒ String?
Returns The client-facing reason why this field is deprecated (if present, the field is deprecated).
      50 51 52  | 
    
      # File 'lib/graphql/field.rb', line 50 def deprecation_reason @deprecation_reason end  | 
  
#description ⇒ String?
Returns The client-facing description of this field.
      47 48 49  | 
    
      # File 'lib/graphql/field.rb', line 47 def description @description end  | 
  
#edge_class ⇒ nil, Class
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.
      94 95 96  | 
    
      # File 'lib/graphql/field.rb', line 94 def edge_class @edge_class end  | 
  
#function ⇒ Object, GraphQL::Function
Returns The function used to derive this field.
      68 69 70  | 
    
      # File 'lib/graphql/field.rb', line 68 def function @function end  | 
  
#hash_key ⇒ Object?
Returns The key to access with obj.[] to resolve this field (overrides #name if present).
      65 66 67  | 
    
      # File 'lib/graphql/field.rb', line 65 def hash_key @hash_key end  | 
  
#introspection=(value) ⇒ Object (writeonly)
      73 74 75  | 
    
      # File 'lib/graphql/field.rb', line 73 def introspection=(value) @introspection = value end  | 
  
#lazy_resolve_proc ⇒ <#call(obj, args, ctx)> (readonly)
Returns A proc-like object which can be called trigger a lazy resolution.
      40 41 42  | 
    
      # File 'lib/graphql/field.rb', line 40 def lazy_resolve_proc @lazy_resolve_proc end  | 
  
#mutation ⇒ GraphQL::Relay::Mutation?
Returns The mutation this field was derived from, if it was derived from a mutation.
      56 57 58  | 
    
      # File 'lib/graphql/field.rb', line 56 def mutation @mutation end  | 
  
#name ⇒ String Also known as: graphql_name
Returns The name of this field on its ObjectType (or InterfaceType).
      43 44 45  | 
    
      # File 'lib/graphql/field.rb', line 43 def name @name end  | 
  
#property ⇒ Symbol?
Returns The method to call on obj to return this field (overrides #name if present).
      62 63 64  | 
    
      # File 'lib/graphql/field.rb', line 62 def property @property end  | 
  
#relay_node_field ⇒ Boolean
Returns True if this is the Relay find-by-id field.
      31 32 33  | 
    
      # File 'lib/graphql/field.rb', line 31 def relay_node_field @relay_node_field end  | 
  
#relay_nodes_field ⇒ Boolean
Returns True if this is the Relay find-by-ids field.
      34 35 36  | 
    
      # File 'lib/graphql/field.rb', line 34 def relay_nodes_field @relay_nodes_field end  | 
  
#resolve_proc ⇒ <#call(obj, args, ctx)> (readonly)
Returns A proc-like object which can be called to return the field’s value.
      37 38 39  | 
    
      # File 'lib/graphql/field.rb', line 37 def resolve_proc @resolve_proc end  | 
  
#subscription_scope ⇒ nil, String
Returns Prefix for subscription names from this field.
      76 77 78  | 
    
      # File 'lib/graphql/field.rb', line 76 def subscription_scope @subscription_scope end  | 
  
#trace ⇒ Boolean
Returns True if this field should be traced. By default, fields are only traced if they are not a ScalarType or EnumType.
      79 80 81  | 
    
      # File 'lib/graphql/field.rb', line 79 def trace @trace end  | 
  
Instance Method Details
#connection? ⇒ Boolean
      88 89 90  | 
    
      # File 'lib/graphql/field.rb', line 88 def connection? @connection end  | 
  
#edges? ⇒ Boolean
      97 98 99  | 
    
      # File 'lib/graphql/field.rb', line 97 def edges? !!@edge_class end  | 
  
#initialize_copy(other) ⇒ Object
      117 118 119 120 121  | 
    
      # File 'lib/graphql/field.rb', line 117 def initialize_copy(other) ensure_defined super @arguments = other.arguments.dup end  | 
  
#introspection? ⇒ Boolean
Returns Is this field a predefined introspection field?.
      124 125 126  | 
    
      # File 'lib/graphql/field.rb', line 124 def introspection? @introspection end  | 
  
#lazy_resolve(obj, args, ctx) ⇒ Object
If #resolve returned an object which should be handled lazily, this method will be called later to force the object to return its value.
      189 190 191  | 
    
      # File 'lib/graphql/field.rb', line 189 def lazy_resolve(obj, args, ctx) @lazy_resolve_proc.call(obj, args, ctx) end  | 
  
#lazy_resolve=(new_lazy_resolve_proc) ⇒ Object
Assign a new resolve proc to this field. Used for #lazy_resolve
      194 195 196  | 
    
      # File 'lib/graphql/field.rb', line 194 def lazy_resolve=(new_lazy_resolve_proc) @lazy_resolve_proc = new_lazy_resolve_proc end  | 
  
#prepare_lazy(obj, args, ctx) ⇒ GraphQL::Execution::Lazy
Prepare a lazy value for this field. It may be then-ed and resolved later.
      200 201 202 203 204  | 
    
      # File 'lib/graphql/field.rb', line 200 def prepare_lazy(obj, args, ctx) GraphQL::Execution::Lazy.new { lazy_resolve(obj, args, ctx) } end  | 
  
#resolve(object, arguments, context) ⇒ Object
Get a value for this field
      135 136 137  | 
    
      # File 'lib/graphql/field.rb', line 135 def resolve(object, arguments, context) resolve_proc.call(object, arguments, context) end  | 
  
#resolve=(new_resolve_proc) ⇒ Object
      142 143 144  | 
    
      # File 'lib/graphql/field.rb', line 142 def resolve=(new_resolve_proc) @resolve_proc = new_resolve_proc || build_default_resolver end  | 
  
#to_s ⇒ Object
      179 180 181  | 
    
      # File 'lib/graphql/field.rb', line 179 def to_s "<Field name:#{name || "not-named"} desc:#{description} resolve:#{resolve_proc}>" end  | 
  
#type ⇒ Object
Get the return type for this field.
      152 153 154  | 
    
      # File 'lib/graphql/field.rb', line 152 def type @clean_type ||= GraphQL::BaseType.(@dirty_type) end  | 
  
#type=(new_return_type) ⇒ Object
      146 147 148 149  | 
    
      # File 'lib/graphql/field.rb', line 146 def type=(new_return_type) @clean_type = nil @dirty_type = new_return_type end  | 
  
#type_class ⇒ Object
      206 207 208  | 
    
      # File 'lib/graphql/field.rb', line 206 def type_class [:type_class] end  |