spec/graphql/execution/instrumentation_spec.rb in graphql-1.8.10 vs spec/graphql/execution/instrumentation_spec.rb in graphql-1.8.11
- old
+ new
@@ -49,10 +49,21 @@
end
class FirstInstrumenter < LogInstrumenter; end
class SecondInstrumenter < LogInstrumenter; end
+ class ExecutionErrorInstrumenter
+ def before_query(query)
+ if query.context[:raise_execution_error]
+ raise GraphQL::ExecutionError, "Raised from instrumenter before_query"
+ end
+ end
+
+ def after_query(query)
+ end
+ end
+
let(:query_type) {
GraphQL::ObjectType.define do
name "Query"
field :int, types.Int do
argument :value, types.Int
@@ -65,10 +76,11 @@
spec = self
GraphQL::Schema.define do
query(spec.query_type)
instrument(:query, FirstInstrumenter.new)
instrument(:query, SecondInstrumenter.new)
+ instrument(:query, ExecutionErrorInstrumenter.new)
end
}
describe "query instrumenters" do
it "before_query of the 2nd instrumenter does not run but after_query does" do
@@ -92,9 +104,16 @@
# But the first instrumenter still got a chance to teardown
assert context[:first_instrumenter_did_begin]
assert context[:first_instrumenter_did_end]
assert context[:second_instrumenter_did_begin]
assert context[:second_instrumenter_did_end]
+ end
+
+ it "rescues execution errors from before_query" do
+ context = {raise_execution_error: true}
+ res = schema.execute(" { int(value: 2) } ", context: context)
+ assert_equal "Raised from instrumenter before_query", res["errors"].first["message"]
+ refute res.key?("data"), "The query doesn't run"
end
end
describe "within a multiplex" do
let(:multiplex_schema) {