Fix covariance checks for SDL type extensions - #4420
Merged
Conversation
Contributor
Test ReportTest Results
Code Coverage (Java 25)
Changed Class Coverage (1 class)
|
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
GraphQL Java incorrectly rejected valid covariant field return types when the subtype relationship was introduced by an SDL extension rather than declared on the base type.
Object extension example
In this schema,
DogimplementsPetthrough an extension. ReturningDogfor a field declared asPetis valid covariance:The schema was incorrectly rejected because the covariance check only inspected the base definition of
Dogand did not seeextend type Dog implements Pet.Interface extension example
The same problem affected interfaces inheriting from other interfaces through extensions:
WorkingPetis a valid covariant return type forPet, but the extension-based relationship was previously ignored.Union extension example
Union members introduced through extensions were also missed:
Dogis a valid subtype ofPets, but the previous check only inspected members declared on the base union.Summary
TypeDefinitionRegistrystores base SDL definitions and extension definitions separately. This change makes the registry use the logical base-plus-extension relationships when:This matches graphql-js behavior. graphql-js materializes extensions into its schema types before subtype checks; GraphQL Java retains separate AST definitions and now combines them when answering the equivalent registry queries.
Wrapped covariance
The same relationship is preserved while recursively checking list and non-null wrappers:
[Dog!]!remains a valid subtype of[Pet]!.Unrelated types remain invalid
Extension relationships are matched by their declared interface and do not make unrelated types compatible:
This schema is still rejected because
CarimplementsVehicle, notPet.