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

Query returns incorrect data when there is a conflict between query field alias and entity key field #3036

Open
cltnschlosser opened this issue Jun 16, 2024 · 0 comments

Comments

@cltnschlosser
Copy link

Issue Description

When a query aliases a field on a fetched entity to the same name as the key of the entity, the server starts to return the wrong data if the query is modified to include fields joined from multiple subgraphs. That's a bit wordy, but I'll break up the reproduction sample here.

Subgraph one defines the entity as:

type Query {
  object: O
}
type O @key(fields: "id") {
  id: ID!
  legacyId: ID
  a: String
}

Then we have a rather simple query here, which uses the legacyId and not the id that is the entity's key. The legacyId is aliased to id which matches the entity's key.

query TestQuery {
  object {
    id: legacyId
    legacyId # Not necessary but used later to focus attention to the issue
    a
  }
}

At this point, everything is fine. Given the following resolver:

resolvers: {
  Query: {
    object() {
      return { __typename: 'O', id: 'newId', legacyId: 'legacyId', a: 'a' };
    },
  },
},

We end up with the expected result:

{
  "object": {
    "a": "a",
    "id": "legacyId",
    "legacyId": "legacyId",
  },
}

Notice id and legacyId are the same (because id is just an alias).

When we introduce a second subgraph that extends this entity, complications arise.

extend type O @key(fields: "id") {
  id: ID!
  a: String @external
  b: String @requires(fields: "a")
}

Modifying our test query to include the new field b:

query TestQuery {
  object {
    id: legacyId
    legacyId # Not necessary but used later to focus attention to the issue
    a
  }
}

Results in the unexpected:

{
  "object": {
    "a": "a",
    "b": "B: a",
    "id": "newId",
    "legacyId": "legacyId",
  },
}

id and legacy no longer match, instead id is replaced with the actual id field and the alias is now longer functioning.

Link to Reproduction

#3035

Reproduction Steps

No response

@cltnschlosser cltnschlosser changed the title Query returns incorrect data when there is a conflict between query field alias and entity id Query returns incorrect data when there is a conflict between query field alias and entity key field Jun 16, 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

1 participant