fix(findSchemaChanges): detect @oneOf added to or removed from an input object type - #4847
Open
eastagiletracker wants to merge 1 commit into
Conversation
|
@eastagiletracker is attempting to deploy a commit to the The GraphQL Foundation Team on Vercel. A member of the Team first needs to authorize it. |
|
Contributor
|
a ping on the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR proposes teaching
findSchemaChangesto detect@oneOfbeing added to or removed from an input object type, which is currently reported as no change at all. We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/349. You can sign in with your GitHub ID to claim ownership of the project.What goes wrong
Adding
@oneOfto an existing input object type is a breaking change: afterwards exactly one field may be supplied and its value must be non-null, so any operation that passed two fields of that input object stops validating.findInputObjectTypeChangesinsrc/utilities/findSchemaChanges.tscompares each input field's type, default value and description, but never comparesisOneOfon the type itself the wayfindDirectiveChangescomparesisRepeatable. As a resultfindSchemaChanges,findBreakingChangesandfindDangerousChangesall return an empty array for that edit, and a schema check built on them waves through a change that breaks every client sending more than one field.isOneOfis observable to clients — it is part of the introspection query,printSchemaemits@oneOf, andbuildClientSchemaround-trips it — so it is in scope for a diff whose stated purpose is comparing "client's observable changes".Reproduction on 17.x.x at 9c24501
The operation validates cleanly against the old schema and is rejected by the new one, and the reported difference between those two schemas is empty. With this change the first two lines become the
INPUT_OBJECT_ONE_OF_ADDEDentry below.The change
findInputObjectTypeChangesnow comparesisOneOf, mirroring theisRepeatablecomparison infindDirectiveChanges, and reports one of two new members:BreakingChangeType.INPUT_OBJECT_ONE_OF_ADDED—@oneOf was added to SearchBy.Requiring exactly one non-null field rejects input values that were previously accepted.SafeChangeType.INPUT_OBJECT_ONE_OF_REMOVED—@oneOf was removed from SearchBy.Every value valid under a OneOf Input Object stays valid once the constraint is lifted, and such a type's fields are already all nullable and default-free, so nothing becomes required in the other direction.The names follow the existing
DIRECTIVE_REPEATABLE_ADDED/DIRECTIVE_REPEATABLE_REMOVEDpair. Both members are additive: no existing member, description string or classification moves, so consumers are unaffected unless they switch exhaustively over the change types. This is the same shape of gap as the input-field default value one closed in #4832, in the same function.website/pages/api-v*are generated snapshots, so the two members are left for the next docs regeneration; the schema-evolution guide reads them throughObject.values(BreakingChangeType)and needs no edit.Verification
Four tests:
@oneOfadded,@oneOfremoved, and an unchanged OneOf Input Object that gains a field (which must still report onlyOPTIONAL_INPUT_FIELD_ADDED) infindSchemaChanges-test.ts, plus one through the publicfindBreakingChangeswrapper infindBreakingChanges-test.ts.Reverting only the new comparison while keeping the two members turns three of them red, and the unchanged-
@oneOfcontrol stays green:Restoring it, all four pass and the rest of the suite is unmoved from the same checks run on a clean 9c24501 tree:
npm run testonlygoes from 3031 passing / 0 failing to 3035 passing / 0 failing, andnpm run testonly:coverkeepsfindSchemaChanges.tsand the project total at 100.00 lines / 100.00 branches / 100.00 functions.npm run check:ts,npm run lint,npm run prettier:checkandnpm run check:spellingare all clean.How this was managed
We tracked this work on a board imported from this repository's issues — 1,170 stories and 15 labels. The story behind this change is https://eastagiletracker.com/projects/349/stories/218725 and the board it sits on is https://eastagiletracker.com/projects/349.
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com