Patch SchemaDiff to apply respective nullability change validation for input vs. output types#2971
Merged
bbakerman merged 4 commits intographql-java:masterfrom Oct 9, 2022
Merged
Conversation
added 4 commits
September 21, 2022 15:15
Moved case Query.being( .. , newArg: String!) from schema_changed_object_fields to schema_changed_input_object_fields. Added case Istari.temperament "non-null to nullable" -> stricter.
Contributor
Author
|
Hi @bbakerman, is this something you can help review? I see you originally wrote SchemaDiff and have looked at a couple other changes to it this year. |
Contributor
Author
|
Hey @bbakerman, is there anything I can/should do to help with respect to this change? |
bbakerman
approved these changes
Oct 9, 2022
Member
bbakerman
left a comment
There was a problem hiding this comment.
Thanks for this excellent and well tested change
Contributor
Author
|
@bbakerman is there have a rough timeline for |
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.
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: