Class: GraphQL::Executor
- Inherits:
-
Object
- Object
- GraphQL::Executor
- Defined in:
- lib/graphql/executor.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #execute(root = {}, params = {}, operation_name = nil) ⇒ Object
-
#initialize(document, schema) ⇒ Executor
constructor
A new instance of Executor.
- #materialize(data) ⇒ Object
Constructor Details
#initialize(document, schema) ⇒ Executor
Returns a new instance of Executor.
6 7 8 9 10 11 12 13 14 |
# File 'lib/graphql/executor.rb', line 6 def initialize(document, schema) @document = document @schema = schema @context = { document: document, schema: schema, errors: [] } end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/graphql/executor.rb', line 4 def context @context end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
4 5 6 |
# File 'lib/graphql/executor.rb', line 4 def document @document end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
4 5 6 |
# File 'lib/graphql/executor.rb', line 4 def schema @schema end |
Instance Method Details
#execute(root = {}, params = {}, operation_name = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/graphql/executor.rb', line 16 def execute(root = {}, params = {}, operation_name = nil) raise GraphQLError, "At least one operation should be defined." if document.operations.size == 0 raise GraphQLError, "Operation name should be defined for more than one operation." if document.operations.size > 1 && operation_name.nil? operation_name = document.operations.first.name if operation_name.nil? operation = document.operation(operation_name) raise GraphQLError, "Operation named '#{operation_name}' not found in document." if operation.nil? context[:root] = root context[:params] = params return materialize(operation.evaluate(context)), context[:errors] end |
#materialize(data) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/graphql/executor.rb', line 31 def materialize(data) case data when Celluloid::Future materialize(data.value) when Hash data.reduce({}) do |memo, pair| memo[pair.first] = materialize(pair.last) memo end when Array data.each_with_index.reduce([]) do |memo, pair| memo[pair.last] = materialize(pair.first) memo end else data end end |