Class: GraphQL::Query::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/query/executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query) ⇒ Executor

Returns a new instance of Executor.



7
8
9
# File 'lib/graphql/query/executor.rb', line 7

def initialize(query)
  @query = query
end

Instance Attribute Details

#queryGraphQL::Query (readonly)

Returns the query being executed.

Returns:



5
6
7
# File 'lib/graphql/query/executor.rb', line 5

def query
  @query
end

Instance Method Details

#resultHash

Evalute operation_name on #query. Handle errors by putting them in the “errors” key. (Or, if ‘query.debug`, by re-raising them.)

Returns:

  • (Hash)

    A GraphQL response, with either a “data” key or an “errors” key



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/graphql/query/executor.rb', line 14

def result
  execute
rescue GraphQL::ExecutionError => err
  {"errors" => [err.to_h]}
rescue GraphQL::Query::OperationNameMissingError => err
  {"errors" => [{"message" => err.message}]}
rescue StandardError => err
  query.debug && raise(err)
  message = "Something went wrong during query execution: #{err}" #\n#{err.backtrace.join("\n  ")}"
  {"errors" => [{"message" => message}]}
end