Class: GQL::Field
- Inherits:
-
Object
- Object
- GQL::Field
- Extended by:
- Mixins::Common
- Includes:
- Mixins::HasCalls, Mixins::HasFields
- Defined in:
- lib/gql/field.rb
Direct Known Subclasses
Array, Connection, Lazy, Object, Scalar, Schema::Call, Schema::CallerClass, Schema::Field, Schema::List, Schema::Parameter
Defined Under Namespace
Classes: ExecutionContext
Instance Attribute Summary collapse
-
#ast_node ⇒ Object
readonly
Returns the value of attribute ast_node.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Class Method Summary collapse
- .build_class(id, proc, options = {}) ⇒ Object
- .execute(parent, ast_node, target, variables, context) ⇒ Object
Instance Method Summary collapse
-
#initialize(ast_node, target, variables, context) ⇒ Field
constructor
A new instance of Field.
- #scalar_value ⇒ Object
- #value ⇒ Object
Methods included from Mixins::Common
Constructor Details
#initialize(ast_node, target, variables, context) ⇒ Field
Returns a new instance of Field.
36 37 38 39 |
# File 'lib/gql/field.rb', line 36 def initialize(ast_node, target, variables, context) @ast_node, @target = ast_node, target @variables, @context = variables, context end |
Instance Attribute Details
#ast_node ⇒ Object (readonly)
Returns the value of attribute ast_node.
34 35 36 |
# File 'lib/gql/field.rb', line 34 def ast_node @ast_node end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
34 35 36 |
# File 'lib/gql/field.rb', line 34 def context @context end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
34 35 36 |
# File 'lib/gql/field.rb', line 34 def target @target end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
34 35 36 |
# File 'lib/gql/field.rb', line 34 def variables @variables end |
Class Method Details
.build_class(id, proc, options = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/gql/field.rb', line 14 def build_class(id, proc, = {}) Class.new(self).tap do |field_class| field_class.id = id.to_s field_class.proc = proc end end |
.execute(parent, ast_node, target, variables, context) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/gql/field.rb', line 21 def execute(parent, ast_node, target, variables, context) args = [target, context, GQL.debug ? parent : nil] target = ExecutionContext.new(*args).instance_exec(&proc) field = new(ast_node, target, variables, context) field.value end |
Instance Method Details
#scalar_value ⇒ Object
51 52 53 |
# File 'lib/gql/field.rb', line 51 def scalar_value nil end |
#value ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/gql/field.rb', line 41 def value if ast_call = ast_node.call value_of_call ast_call elsif ast_fields = ast_node.fields value_of_fields ast_fields else scalar_value end end |