Class: GraphQL::Query::Executor

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

Defined Under Namespace

Classes: OperationNameMissingError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, operation_name) ⇒ Executor

Returns a new instance of Executor.



18
19
20
21
# File 'lib/graphql/query/executor.rb', line 18

def initialize(query, operation_name)
  @query = query
  @operation_name = operation_name
end

Instance Attribute Details

#operation_nameString (readonly)

Returns the operation to run in #query.

Returns:

  • (String)

    the operation to run in #query



15
16
17
# File 'lib/graphql/query/executor.rb', line 15

def operation_name
  @operation_name
end

#queryGraphQL::Query (readonly)

Returns the query being executed.

Returns:



12
13
14
# File 'lib/graphql/query/executor.rb', line 12

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



26
27
28
29
30
31
32
33
34
# File 'lib/graphql/query/executor.rb', line 26

def result
  execute
rescue 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