Error paths and locations are duplicated with duplicate queries that error lazily
juanrgon opened this issue · 0 comments
Describe the bug
Error paths and locations are duplicated with duplicate queries that error lazily.
I provided a simple script to reproduce this issue. It uses a simple single field schema with a dataloader that always resolves to an error:
require 'graphql'
require 'json'
class ItemLoader < GraphQL::Dataloader::Source
def fetch(keys)
keys.map { |key| GraphQL::ExecutionError.new("Error for #{key}") }
end
end
class QueryType < GraphQL::Schema::Object
field :item, String do
argument :key, String
end
def item(key:)
dataloader.with(ItemLoader).load(key)
end
end
class Schema < GraphQL::Schema
query QueryType
use GraphQL::Dataloader
end
query = <<-GRAPHQL
query {
query0: item(key: "a")
query1: item(key: "a")
}
GRAPHQL
result = Schema.execute(query)
puts JSON.pretty_generate(result.to_h)
When running the above, I would expect to see the following:
{
"errors": [
{
"message": "Error for a",
"locations": [
{
"line": 2,
"column": 5
}
],
"path": [
"query0"
]
},
{
"message": "Error for a",
"locations": [
{
"line": 3,
"column": 5
}
],
"path": [
"query1"
]
}
],
"data": {
"query0": null,
"query1": null
}
}
but instead, I'm seeing this:
{
"errors": [
{
"message": "Error for a",
"locations": [
{
"line": 2,
"column": 5
}
],
"path": [
"query0"
]
},
{
"message": "Error for a",
"locations": [
{
"line": 2,
"column": 5
}
],
"path": [
"query0"
]
}
],
"data": {
"query0": null,
"query1": null
}
}
Versions
graphql
version: 2.3.9
GraphQL schema
class ItemLoader < GraphQL::Dataloader::Source
def fetch(keys)
keys.map { |key| GraphQL::ExecutionError.new("Error for #{key}") }
end
end
class QueryType < GraphQL::Schema::Object
field :item, String do
argument :key, String
end
def item(key:)
dataloader.with(ItemLoader).load(key)
end
end
class Schema < GraphQL::Schema
query QueryType
use GraphQL::Dataloader
end
GraphQL query
Example GraphQL query and response (if query execution is involved)
query {
query0: item(key: "a")
query1: item(key: "a")
}
{
"errors": [
{
"message": "Error for a",
"locations": [
{
"line": 2,
"column": 5
}
],
"path": [
"query0"
]
},
{
"message": "Error for a",
"locations": [
{
"line": 2,
"column": 5
}
],
"path": [
"query0"
]
}
],
"data": {
"query0": null,
"query1": null
}
}
Steps to reproduce
The script I provided at the beginning of this issue is all you need
Expected behavior
I expect error paths and locations for all fields to be unique per field
Actual behavior
I'm seeing error paths and locations for duplicate queries/fields duplicated, instead of being unique