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

Fix fed1 schema upgraded when @external is on a type. #2343

Merged
merged 2 commits into from
Jan 23, 2023

Conversation

pcmanus
Copy link
Contributor

@pcmanus pcmanus commented Jan 20, 2023

For historical reasons, @external was legal to put on an object type since about forever (even in federation 1) but it used to be completely ignored. We "fixed" this support in #2214, but to limit surprised on upgrades from fed1, the schema upgrader had been modified to drop any @external on an object type (since again, those were legal but ignored in fed1). However, the code for adding @Shareable in that same schema upgrader was not updated correctly and so it was taking @external on types into account, and thus it ended up not adding @shareable in some cases where it should have.

@netlify
Copy link

netlify bot commented Jan 20, 2023

👷 Deploy request for apollo-federation-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit d63fc8e

@changeset-bot
Copy link

changeset-bot bot commented Jan 20, 2023

🦋 Changeset detected

Latest commit: d63fc8e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@apollo/federation-internals Patch
@apollo/gateway Patch
@apollo/composition Patch
@apollo/query-planner Patch
@apollo/query-graphs Patch
@apollo/subgraph Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pcmanus pcmanus self-assigned this Jan 20, 2023
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 20, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

For historical reasons, `@external` was legal to put on an object type
since about forever (even in federation 1) but it used to be completely
ignored. We "fixed" this support in apollographql#2214, but to limit surprised on
upgrades from fed1, the schema upgrader had been modified to drop any
`@external` on an object type (since again, those were legal but ignored
in fed1). However, the code for adding @Shareable in that same schema
upgrader was not updated correctly and so it _was_ taking `@external`
on types into account, and thus it ended up _not_ adding `@shareable`
in some cases where it should have.
@pcmanus pcmanus force-pushed the external-on-types-upgrade-fix branch from 94eeaa7 to 8d8c40d Compare January 20, 2023 10:55
@pcmanus pcmanus added this to the 2.3.0 milestone Jan 20, 2023
Copy link
Member

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple minor comments on the documentation.

Comment on lines 1830 to 1835
// We do not collect @external on types for fed1 schema as those are ignored and will be discarded by the schema upgrader
// Do note however that the schema upgrader relying on the methods of this tester to figure out if a subgraph resolves
// a field in order to know when @shareable should be automatically added, hence the need for the short-cut here.
if (!this.isFed2Schema) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own understanding I've rewritten this comment a bit. Is this correct, and if so would you consider using it here or updating yours a bit? Your PR description explains this but the comment misses this part which was important for me to understand it:

In the fed1 case, if the map is populated then @shareable won't be added in places where it should have.

My interpretation / suggestion:
We do not collect @external on types for fed1 schema since those will be discarded by the schema upgrader.
The schema upgrader relies on the populated externalFieldsOnType object to inform when @shareable should be automatically added. In the fed1 case, if the map is populated then @shareable won't be added in places where it should have.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updates are correct, and are probably clearer; made the change.

"@apollo/federation-internals": patch
---

Fix fed1 schema upgraded when `@external` is on a type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure a user reading this will understand how this affects their usage. I think the context in your PR description would be useful here (and in the manual changelog entries).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this wasn't that helpful as it could be. I've reworded it so it's more obvious for a user if they may be affected or not by this and care about.

@pcmanus pcmanus merged commit 282c563 into apollographql:main Jan 23, 2023
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 this pull request may close these issues.

2 participants