Skip to content

Commit

Permalink
Add multiple errors test
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Dec 10, 2024
1 parent 9cc47f5 commit 385ee3b
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions spec/graphql/query/partial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" }]}])
Expand Down

0 comments on commit 385ee3b

Please sign in to comment.