Generate federation entity resolvers for interfaces with @key fields defined #2634
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.
When using interfaces and interfaceObjects as described by the Apollo spec you have to be able to resolve the interface types as described here.
This updates the generation to allow
@key
fields on interfaces and generates the resulting functions needed to handling resolving the entities.I left the existing test but changed it to be an unused interface, and then created a new test with an interface that is used to verify it works. I've also validated this works with the federated gateway to properly handle resolving interface return types coming from a different subgraph.
The only thing I'm not sure about is around line 223. I'm using an object that implements the interface to get the field types. This seemed easier to maintain long term as it seemed like I would need to fork to code and have one path for an interface and one path for an object since there isn't an object for the interface. Open to ideas to improve this though.
Not sure if any docs specifically for this are desired, the use of
@key
fields is documented already and it follows the same pattern.I have: