Patch SchemaDiff to apply respective nullability change validation for input vs. output types #2971
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.
Description
SchemaDiff had a single method
checkTypeWithNonNullAndListthat always applied the rule "non-null to nullable is safe; nullable to non-null is breaking."This is true for input types and arguments, but the opposite should be true for fields on output types -- "nullable to non-null is safe; non-null to nullable is breaking."
A consumer operating on a nullable field should already be checking for presence, and adding an additional guarantee of non-null is safe.
A consumer operating on a non-null field may not be checking for presence, and removing the guarantee of non-null may break when that field is null.
Implementation
Two methods are defined -- one for input and argument types, and one for output types.
The methods are rewritten in a style of handling three top-level cases for the old type (non-null, list, and neither), and within each case handling the cases for the new type.
Calls to the previous method are updated to their respective new versions.
graphql-js implementation for reference:
isChangeSafeForObjectOrInterfaceField
isChangeSafeForInputObjectFieldOrFieldArg
Testing
Unit tests for the new methods are updated and added:
schema_ABaseLine:
schema_changed_input_object_fields:
schema_changed_object_fields: