From 385ee3bd74cae37c0d21612455b397cefd365d63 Mon Sep 17 00:00:00 2001 From: Robert Mosolgo Date: Tue, 10 Dec 2024 09:56:34 -0500 Subject: [PATCH] Add multiple errors test --- spec/graphql/query/partial_spec.rb | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/spec/graphql/query/partial_spec.rb b/spec/graphql/query/partial_spec.rb index f34b1ac864..e620b7be8c 100644 --- a/spec/graphql/query/partial_spec.rb +++ b/spec/graphql/query/partial_spec.rb @@ -113,11 +113,24 @@ def run_partials(string, partial_configs) end it "returns errors if they occur" do - str = "{ farm1: farm(id: \"1\") { error } }" - results = run_partials(str, [{ path: ["farm1"], object: PartialSchema::Database::FARMS["1"] }]) - assert_nil results.first.fetch("data").fetch("error") - assert_equal [["This is a field error"]], results.map { |r| r["errors"].map { |err| err["message"] } } - assert_equal [[["error"]]], results.map { |r| r["errors"].map { |err| err["path"] } } + str = "{ + farm1: farm(id: \"1\") { error } + farm2: farm(id: \"1\") { name } + farm3: farm(id: \"1\") { name fieldError: error } + }" + results = run_partials(str, [ + { path: ["farm1"], object: PartialSchema::Database::FARMS["1"] }, + { path: ["farm2"], object: PartialSchema::Database::FARMS["2"] }, + { path: ["farm3"], object: PartialSchema::Database::FARMS["3"] }, + ]) + + assert_equal [{"message"=>"This is a field error", "locations"=>[{"line"=>2, "column"=>30}], "path"=>["error"]}], results[0]["errors"] + refute results[1].key?("errors") + assert_equal [{"message"=>"This is a field error", "locations"=>[{"line"=>4, "column"=>35}], "path"=>["fieldError"]}], results[2]["errors"] + + assert_equal({ "error" => nil }, results[0]["data"]) + assert_equal({ "name" => "Henley's Orchard" }, results[1]["data"]) + assert_equal({ "name" => "Wenger Grapes", "fieldError" => nil }, results[2]["data"]) end it "raises errors when given nonexistent paths" do @@ -164,8 +177,6 @@ def run_partials(string, partial_configs) assert_equal [[:mget, ["1", "2"]], [:mget, ["3"]]], PartialSchema::Database.log end - it "returns multiple errors concurrently" - it "runs arrays and returns useful metadata in the result" do str = "{ farms { name } }" results = run_partials(str, [{ path: ["farms"], object: [{ name: "Twenty Paces" }, { name: "Spring Creek Blooms" }]}])