Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error paths and locations are duplicated with duplicate queries that error lazily #5020

Closed
juanrgon opened this issue Jul 15, 2024 · 0 comments · Fixed by #5021
Closed

Error paths and locations are duplicated with duplicate queries that error lazily #5020

juanrgon opened this issue Jul 15, 2024 · 0 comments · Fixed by #5021

Comments

@juanrgon
Copy link
Contributor

juanrgon commented Jul 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant