-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Aliased field is cached differently based on order #12283
Comments
I think you might be breaking a base assumption of GraphQL about data integrity here - I don't think that this response is valid in the world of GraphQL:
(assuming that both Since both of these have the same source field with the same arguments, they describe the same object - if you were to return The cache certainly doesn't handle the case - we assume that if you return To me this feels as if you're working around a problem, probably using the wrong tool for the job, based on a prior assumption (a bit of an xy-problem maybe). Could you explain a bit more why you are actually doing this? Maybe we can identify a better tool for the job together. |
Hi @phryneas , thanks for you response!
Let me clarify our use case. Subgraph A attempts to resolve an entity from another subgraph, B. If the entity has been deleted, subgraph B returns null. In our scenario, we want to inform users that the entity was deleted (as opposed to never existing) and display the ID of the deleted entity. We achieve this by using a streamlined query that requests only the id, ensuring that subgraph B is not required for resolution. |
I've seen the reproduction before I answered yesterday - I'm not surprised by the result. Your response contains conflicting information. I'll lay it out a bit more: The order of operations here is
Or more closely - let's assume that In case A:
In case B:
The fact that you are aliasing it in the query is a transport-level concern, but doesn't matter for storage. The cache doesn't care about the alias, otherwise you could accidentally use aliases to overwrite other fields by their name or things like that. Imagine a query like
Honestly, that sounds like an abuse of an implementation detail - as I said, we assume that a GraphQL response is consistent within itself and this will break that assumption. I would suggest that you create a new Query field like |
Since this is not an issue with Apollo Client, I'm going to go ahead and close this issue. Please let us know if you need any more help. Thanks! |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
Issue Description
In our app, we sometime use alias to get the full details of objects the might be deleted, and the actual field to get just the
id
, which is always returned.Seems like the cache behaves differently based on the order.
For example, let's say that
personDetails
is returnednull
andperson
returns{id: "1"}
.if queried in the following order, we get
null
on both fields, even though the server did return value forperson
If the order is flipped, it seems work as expected:
Link to Reproduction
https://codesandbox.io/p/devbox/distracted-neumann-cnz2rt?workspaceId=ws_3d3S1CmTc7BCJtbnRB7BQC
Reproduction Steps
No response
@apollo/client
version3.11.8
The text was updated successfully, but these errors were encountered: