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

Ordering of @key directives causing different behaviors and planning failure #2987

Open
rruizt opened this issue Apr 2, 2024 · 1 comment

Comments

@rruizt
Copy link

rruizt commented Apr 2, 2024

Hello!

Describe the bug

To Reproduce
Steps to reproduce the behavior:

  1. Setup 3 subgraphs:

Subgraph 1

extend schema
@link(url: "https://specs.apollo.dev/federation/v2.3",
  import: ["@key", "@shareable", "@override", "@external", "@extends", "@inaccessible", "@requires"])

type Query {
  own: Storage
}

type Storage @key(fields: "id"){
  id: ID!
}

type Product @key(fields: "id") @key(fields: "uid") {
  id: ID!
  uid: ID!
  colour: Boolean @external
  type: String! @requires(fields: "colour")
}

Subgraph 2

extend schema
@link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key", "@external", "@extends", "@interfaceObject"])

type Storage @key(fields: "id") @extends {
  id: ID! @external
  shelves: [Shelve!]
}

type Shelve @key(fields: "id") {
  id: ID!
  product: Product!
}

type Product @key(fields: "uid", resolvable: false) {
  uid: ID!
}

Subgraph 3

extend schema @link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key", "@external", "@extends", "@requires", "@inaccessible"])

type Product @key(fields: "uid") @extends {
  uid: ID! @external
  colour: Boolean @inaccessible
}
  1. Submit request
{
  own {
    shelves {
      product {
        type
      }
    }
  }
}
  1. See error
{
  "data": {},
  "errors": [
    {
      "message": "value retrieval failed: router bridge error: the deno runtime raised an error: `request: couldn't receive response couldn't deserialize payload `16976028778059605818`: `deno: couldn't deserialize response : `Error(\"invalid neither null nor empty object: found Object {\\\"code\\\": String(\\\"QUERY_PLANNING_FAILED\\\"), \\\"exception\\\": Object {\\\"stacktrace\\\": Array [String(\\\"Cannot add selection of field \\\\\\\"Product.id\\\\\\\" to selection set of parent type \\\\\\\"Product\\\\\\\"\\\")]}}\", line: 0, column: 0)``.`",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR"
      }
    }
  ]
}

Expected behavior
Router comes back with a working plan

Additional context
Composed the supergraph with rover v0.23.0
I tested it with Apollo Router version 1.43.0

I found two workarounds:

  1. Add @key(fields: "id") to the Product types in subgraph 2 and 3
  2. Move the @key(fields: "uid") in front of the id one on subgraph 1
type Product @key(fields: "uid") @key(fields: "id")  {
....
}

Thank you so much for your work!

@Geal Geal transferred this issue from apollographql/router Apr 22, 2024
@Geal
Copy link
Contributor

Geal commented Apr 22, 2024

hi! I'm transferring this over to the federation repository, where our planner work is happening. We will look into this issue, but it might take some time to get back to you on this

@abernix abernix changed the title QUERY_PLANNING_FAILED related to multiple @key directives Ordering of @key directives causing different behaviors and planning failure Apr 22, 2024
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

No branches or pull requests

2 participants