Class: GQL::Call
- Inherits:
-
Object
- Object
- GQL::Call
- Defined in:
- lib/gql/call.rb
Defined Under Namespace
Classes: Method
Instance Attribute Summary collapse
-
#ast_node ⇒ Object
readonly
Returns the value of attribute ast_node.
-
#caller ⇒ Object
readonly
Returns the value of attribute caller.
-
#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
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(caller, ast_node, target, variables, context) ⇒ Call
constructor
A new instance of Call.
Constructor Details
#initialize(caller, ast_node, target, variables, context) ⇒ Call
Returns a new instance of Call.
50 51 52 53 |
# File 'lib/gql/call.rb', line 50 def initialize(caller, ast_node, target, variables, context) @caller, @ast_node, @target = caller, ast_node, target @variables, @context = variables, context end |
Instance Attribute Details
#ast_node ⇒ Object (readonly)
Returns the value of attribute ast_node.
48 49 50 |
# File 'lib/gql/call.rb', line 48 def ast_node @ast_node end |
#caller ⇒ Object (readonly)
Returns the value of attribute caller.
48 49 50 |
# File 'lib/gql/call.rb', line 48 def caller @caller end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
48 49 50 |
# File 'lib/gql/call.rb', line 48 def context @context end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
48 49 50 |
# File 'lib/gql/call.rb', line 48 def target @target end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
48 49 50 |
# File 'lib/gql/call.rb', line 48 def variables @variables end |
Class Method Details
.build_class(id, result_class, method) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gql/call.rb', line 18 def build_class(id, result_class, method) if result_class.is_a? ::Array if result_class.size == 1 result_class.unshift GQL.default_list_class || Connection end list_class, item_class = result_class unless list_class <= Connection raise Errors::InvalidNodeClass.new(list_class, Connection) end unless item_class <= Node raise Errors::InvalidNodeClass.new(list_class, Node) end = { list_class: list_class, item_class: item_class } result_class = Connection.build_class(:result, nil, ) elsif result_class && !(result_class <= Node) raise Errors::InvalidNodeClass.new(result_class, Node) end Class.new(self).tap do |call_class| call_class.id = id.to_s call_class.method = method call_class.result_class = result_class end end |
Instance Method Details
#execute ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/gql/call.rb', line 55 def execute args = substitute_variables(ast_node.arguments) method = Method.new(target, context) target = method.execute(self.class.method, args) result_class = self.class.result_class || caller.class result = result_class.new(ast_node, target, variables, context) result.value end |