Class: GraphQL::Execution::Interpreter
- Inherits:
-
Object
- Object
- GraphQL::Execution::Interpreter
- Defined in:
- lib/graphql/execution/interpreter.rb,
lib/graphql/execution/interpreter/resolve.rb,
lib/graphql/execution/interpreter/runtime.rb,
lib/graphql/execution/interpreter/arguments.rb,
lib/graphql/execution/interpreter/argument_value.rb,
lib/graphql/execution/interpreter/arguments_cache.rb,
lib/graphql/execution/interpreter/execution_errors.rb,
lib/graphql/execution/interpreter/handles_raw_value.rb
Defined Under Namespace
Modules: Resolve Classes: ArgumentValue, Arguments, ArgumentsCache, ExecutionErrors, ListResultFailedError, RawValue, Runtime
Class Method Summary collapse
-
.begin_multiplex(multiplex) ⇒ Object
-
.begin_query(query, multiplex) ⇒ Object
-
.finish_multiplex(_results, multiplex) ⇒ Object
-
.finish_query(query, _multiplex) ⇒ Object
-
.use(schema_class) ⇒ Object
Instance Method Summary collapse
-
#evaluate(query) ⇒ Interpreter::Runtime
Run the eager part of
query
. -
#execute(_operation, _root_type, query) ⇒ Object
Support
Executor
:S. -
#initialize ⇒ Interpreter
constructor
A new instance of Interpreter.
-
#sync_lazies(query: nil, multiplex: nil) ⇒ void
Run the lazy part of
query
ormultiplex
.
Constructor Details
#initialize ⇒ Interpreter
Returns a new instance of Interpreter.
14 15 |
# File 'lib/graphql/execution/interpreter.rb', line 14 def initialize end |
Class Method Details
.begin_multiplex(multiplex) ⇒ Object
36 37 38 39 40 |
# File 'lib/graphql/execution/interpreter.rb', line 36 def self.begin_multiplex(multiplex) # Since this is basically the batching context, # share it for a whole multiplex multiplex.context[:interpreter_instance] ||= self.new end |
.begin_query(query, multiplex) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/graphql/execution/interpreter.rb', line 42 def self.begin_query(query, multiplex) # The batching context is shared by the multiplex, # so fetch it out and use that instance. interpreter = query.context.namespace(:interpreter)[:interpreter_instance] = multiplex.context[:interpreter_instance] interpreter.evaluate(query) query end |
.finish_multiplex(_results, multiplex) ⇒ Object
52 53 54 55 |
# File 'lib/graphql/execution/interpreter.rb', line 52 def self.finish_multiplex(_results, multiplex) interpreter = multiplex.context[:interpreter_instance] interpreter.sync_lazies(multiplex: multiplex) end |
.finish_query(query, _multiplex) ⇒ Object
57 58 59 60 61 |
# File 'lib/graphql/execution/interpreter.rb', line 57 def self.finish_query(query, _multiplex) { "data" => query.context.namespace(:interpreter)[:runtime].final_result } end |
.use(schema_class) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/graphql/execution/interpreter.rb', line 24 def self.use(schema_class) if schema_class.interpreter? definition_line = caller(2, 1).first GraphQL::Deprecation.warn("GraphQL::Execution::Interpreter is now the default; remove `use GraphQL::Execution::Interpreter` from the schema definition (#{definition_line})") else schema_class.query_execution_strategy(self) schema_class.mutation_execution_strategy(self) schema_class.subscription_execution_strategy(self) schema_class.add_subscription_extension_if_necessary end end |
Instance Method Details
#evaluate(query) ⇒ Interpreter::Runtime
Run the eager part of query
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/graphql/execution/interpreter.rb', line 65 def evaluate(query) # Although queries in a multiplex _share_ an Interpreter instance, # they also have another item of state, which is private to that query # in particular, assign it here: runtime = Runtime.new(query: query) query.context.namespace(:interpreter)[:runtime] = runtime query.trace("execute_query", {query: query}) do runtime.run_eager end runtime end |
#execute(_operation, _root_type, query) ⇒ Object
Support Executor
:S
18 19 20 21 22 |
# File 'lib/graphql/execution/interpreter.rb', line 18 def execute(_operation, _root_type, query) runtime = evaluate(query) sync_lazies(query: query) runtime.final_result end |
#sync_lazies(query: nil, multiplex: nil) ⇒ void
This method returns an undefined value.
Run the lazy part of query
or multiplex
.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/graphql/execution/interpreter.rb', line 81 def sync_lazies(query: nil, multiplex: nil) tracer = query || multiplex if query.nil? && multiplex.queries.length == 1 query = multiplex.queries[0] end queries = multiplex ? multiplex.queries : [query] final_values = queries.map do |query| runtime = query.context.namespace(:interpreter)[:runtime] # it might not be present if the query has an error runtime ? runtime.final_result : nil end final_values.compact! tracer.trace("execute_query_lazy", {multiplex: multiplex, query: query}) do Interpreter::Resolve.resolve_all(final_values, multiplex.dataloader) end queries.each do |query| runtime = query.context.namespace(:interpreter)[:runtime] if runtime runtime.delete_interpreter_context(:current_path) runtime.delete_interpreter_context(:current_field) runtime.delete_interpreter_context(:current_object) runtime.delete_interpreter_context(:current_arguments) end end nil end |