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

Querying fragments result in incorrect downstream requests #2092

Closed
hrkfdn opened this issue Aug 24, 2022 · 3 comments · Fixed by #2098
Closed

Querying fragments result in incorrect downstream requests #2092

hrkfdn opened this issue Aug 24, 2022 · 3 comments · Fixed by #2098
Assignees
Labels

Comments

@hrkfdn
Copy link

hrkfdn commented Aug 24, 2022

Describe the bug
It appears that while fragments in queries are resolved correctly, they are substituted inside the query while the fragment is still sent to the downstream service. This will result in an UnusedFragment validation error in the downstream service.

This appears to be a regression in Apollo Router 0.16.0, as the problem does not occur with 0.15.1.

To Reproduce
Steps to reproduce the behavior:

  1. Setup services
type EMSLicense {
  licenseNumber: String
}

type Employee @key(fields : "id") {
  driverLicense: EMSLicense
  passengerTransportLicense: EMSLicense
}
  1. Submit request
query Employee($id: ID!) {
  employee(id: $id) {
    ...Employee
  }
}

fragment Employee on Employee {
  driverLicense {
    ...EMSLicense
  }
  passengerTransportLicense {
    ...EMSLicense
  }
}

fragment EMSLicense on EMSLicense {
  licenseNumber
}
  1. Results in the following downstream query
query Employee__driver_ems__0($id: ID!) {
  employee(id: $id) {
    driverLicense {
      ... on EMSLicense {
        licenseNumber
      }
    }
    passengerTransportLicense {
      ... on EMSLicense {
        licenseNumber
      }
    }
  }
}
fragment EMSLicense on EMSLicense {
  licenseNumber
}

Desktop (please complete the following information):

  • Apollo Router Version 0.16.0
@hrkfdn hrkfdn added the triage label Aug 24, 2022
@abernix
Copy link
Member

abernix commented Aug 24, 2022

Thanks for reporting this! This may be an upstream bug as it aligns with an update to our federation v2.1.0 query planner. I'm going to check with another set of people and circle back to this.

@abernix abernix transferred this issue from apollographql/router Aug 25, 2022
@abernix
Copy link
Member

abernix commented Aug 25, 2022

I've transferred this to the federation repository where it can be looked at by the query planner team. We'll still need to update the Router (where this was opened originally) if a fix is applied, so let's be sure to communicate when that's ready if that happens. Thanks!

@pcmanus
Copy link
Contributor

pcmanus commented Aug 25, 2022

That was indeed an issue with the query planner code, and more precisely due to an issue with #1911.

Tl;dr, that earlier PR make it so that we now re-use query fragments in subgraph fetches when it make sense, so the fact that the EMSLicense fragment in the example above is present is now expected, but the unexpected part is that this fragment is not actually used in the query, and that was due to some code path re-expanding fragments mistakenly. Pushed #2098 with the fix.

@pcmanus pcmanus self-assigned this Aug 25, 2022
pcmanus pushed a commit to pcmanus/federation that referenced this issue Aug 26, 2022
The code from apollographql#1911 ensures that named fragments from the user query are
reused in subgraph query "when appropriate", but there were some code
path where a fragment that was reused (correctly) could end up be
"re-expanded" (due to an existing method not handling spreads properly).

The resulting subgraph query ended up with the fragment definition
existing but never being used, which is invalid in graphQL.

This patch ensures that a reused fragment is not mistakenly re-expanded
by the code (and thus avoids a query with unused fragments).

Fixes apollographql#2092
pcmanus pushed a commit that referenced this issue Aug 26, 2022
The code from #1911 ensures that named fragments from the user query are
reused in subgraph query "when appropriate", but there were some code
path where a fragment that was reused (correctly) could end up be
"re-expanded" (due to an existing method not handling spreads properly).

The resulting subgraph query ended up with the fragment definition
existing but never being used, which is invalid in graphQL.

This patch ensures that a reused fragment is not mistakenly re-expanded
by the code (and thus avoids a query with unused fragments).

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

Successfully merging a pull request may close this issue.

3 participants