fix __typename not selected if already selected with alias #5963
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
The
TransformCompositeFields
allows to transform fields, which automatically adds__typename
to the selection set.Problem is that to avoid duplicating the selection of this field, we check if it's already selected. This check is flawed because it doesn't take in account the possible alias, which leads to
__typename
not being selected if already present in the query with an alias.This causes incompatibility with the response-cache plugin which rely on selecting
__typename
, but with a__responseCacheType
alias.Related ardatan/graphql-mesh#6272
Type of change
Further comments
A better fix would have been to do exactly what response-cache plugin is doing, always adding typename but with a uniq identifiable alias. This would simplify code and allow for result clean up. But since the usage of this transform is already spreaded and used as is, changing the assumption that a
__typename
is always present would break a lot of other transforms.