Skip to content

Commit cd333a9

Browse files
committed
Migrate more tests
1 parent 3d5582c commit cd333a9

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

spec/graphql/query_spec.rb

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -254,48 +254,52 @@
254254
end
255255
end
256256

257-
describe "after_query hooks" do
258-
module Instrumenter
257+
describe "queries in execute_mutation hooks" do
258+
module ErrorLogTrace
259259
ERROR_LOG = []
260-
def self.before_query(q); end;
261-
def self.after_query(q); ERROR_LOG << q.result["errors"]; end;
260+
def execute_multiplex(multiplex:)
261+
super
262+
ensure
263+
multiplex.queries.each do |q|
264+
ERROR_LOG << q.result["errors"]
265+
end
266+
end
262267
end
263268

264269
let(:schema) {
265270
Class.new(Dummy::Schema) {
266-
instrument(:query, Instrumenter)
271+
trace_with(ErrorLogTrace)
267272
}
268273
}
269274

275+
before do
276+
ErrorLogTrace::ERROR_LOG.clear
277+
end
270278
it "can access #result" do
271-
Instrumenter::ERROR_LOG.clear
272279
result
273-
assert_equal [nil], Instrumenter::ERROR_LOG
280+
assert_equal [nil], ErrorLogTrace::ERROR_LOG
274281
end
275282

276283
it "can access result from an unhandled error" do
277-
Instrumenter::ERROR_LOG.clear
278284
query = GraphQL::Query.new(schema, "{ error }")
279285
assert_raises RuntimeError do
280286
query.result
281287
end
282-
assert_equal [nil], Instrumenter::ERROR_LOG
288+
assert_equal [nil], ErrorLogTrace::ERROR_LOG
283289
end
284290

285291
it "can access result from an handled error" do
286-
Instrumenter::ERROR_LOG.clear
287292
query = GraphQL::Query.new(schema, "{ executionError }")
288293
query.result
289294
expected_err = {
290295
"message" => "There was an execution error",
291296
"locations" => [{"line"=>1, "column"=>3}],
292297
"path" => ["executionError"]
293298
}
294-
assert_equal [[expected_err]], Instrumenter::ERROR_LOG
299+
assert_equal [[expected_err]], ErrorLogTrace::ERROR_LOG
295300
end
296301

297302
it "can access static validation errors" do
298-
Instrumenter::ERROR_LOG.clear
299303
query = GraphQL::Query.new(schema, "{ noField }")
300304
query.result
301305
expected_err = {
@@ -304,33 +308,35 @@ def self.after_query(q); ERROR_LOG << q.result["errors"]; end;
304308
"path" => ["query", "noField"],
305309
"extensions" => {"code"=>"undefinedField", "typeName"=>"Query", "fieldName"=>"noField"},
306310
}
307-
assert_equal [[expected_err]], Instrumenter::ERROR_LOG
311+
assert_equal [[expected_err]], ErrorLogTrace::ERROR_LOG
308312
end
309313
end
310314

311315
describe "when an error propagated through execution" do
312-
module ExtensionsInstrumenter
316+
module ExtensionsTrace
313317
LOG = []
314-
def self.before_query(q); end;
315-
316-
def self.after_query(q)
317-
q.result["extensions"] = { "a" => 1 }
318-
LOG << :ok
318+
def execute_multiplex(multiplex:)
319+
super
320+
ensure
321+
multiplex.queries.each do |q|
322+
q.result["extensions"] = { "a" => 1 }
323+
LOG << :ok
324+
end
319325
end
320326
end
321327

322328
let(:schema) {
323329
Class.new(Dummy::Schema) {
324-
instrument(:query, ExtensionsInstrumenter)
330+
trace_with(ExtensionsTrace)
325331
}
326332
}
327333

328334
it "can add to extensions" do
329-
ExtensionsInstrumenter::LOG.clear
335+
ExtensionsTrace::LOG.clear
330336
assert_raises(RuntimeError) do
331337
schema.execute "{ error }"
332338
end
333-
assert_equal [:ok], ExtensionsInstrumenter::LOG
339+
assert_equal [:ok], ExtensionsTrace::LOG
334340
end
335341
end
336342
end

0 commit comments

Comments
 (0)