Detect REQUIRED_ARG_ADDED when the old field had no prior arguments - #1976
Open
yaroslavGoncharuk wants to merge 2 commits into
Open
yaroslavGoncharuk wants to merge 2 commits into
yaroslavGoncharuk wants to merge 2 commits into
Conversation
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.
Problem
BreakingChangesFinder::findArgChanges()fails to reportREQUIRED_ARG_ADDEDwhen anew required argument is added to a field that had zero arguments in the old
schema. The same kind of change is detected correctly the moment the field already
had at least one argument.
Root cause
The "check if arg was added to the field" loop was nested inside the loop over the
old field's existing args:
Since the "was an arg added" check only ran as a side effect of iterating
$oldField->args, an empty$oldField->argsskipped it entirely — regardless ofhow many args (required or not) the new field had.
Fix
Moved the "was an arg added" loop out from under
foreach ($oldField->args as $oldArgDef)so it runs once per field regardless of whether the old field had anyargs — pure reordering, no behavior change for the already-working (non-empty
old-args) case. Mirrors how
findFieldsThatChangedTypeOnInputObjectTypes()alreadytreats its own "was a field added" check as an independent loop.
Tests
Added
testShouldDetectIfANonNullFieldArgumentWasAddedToAFieldWithNoPriorArgs()alongside the existing
testShouldDetectIfANonNullFieldArgumentWasAdded(), coveringthe old-field-has-zero-args case.
Verification
composer test(2015 tests) andphpstan(full analysis) both pass;php-cs-fixerreports 0 issues on the changed files. (
composer check'srectorstep currentlyerrors on a clean, unmodified
mastertoo — an unrelated pre-existing tooling issue,not run by CI.)
No public API changes; this only makes an existing detection function more complete.