-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parent fields are not available from readField in merge functions #374
Comments
@ab-pm Here's a comment from the source code that attempts to rationalize this decision: The current recommendation is to use the I would be open to exposing an What do you think about that? |
I don't understand how those would be choices. It should be the parent object of the field, which is not ambiguous. One can already easily access field values of the existing and incoming objects through
Oh, that's a very good point I had not though of. However, I was intending to only read constant properties with primitive values from the parent object, which would never be updated.
I'd be very happy to have that available! And it would seem cleaner to always explicitly pass that as the second argument to |
I've run into a similar issue in a merge function where I'm getting Having access to an entity field in the options would resolve my issue as I'm trying to read the parent node out of the cache. In my case, I don't care if this information is stale as the id field will never change. |
The docs at https://www.apollographql.com/docs/react/caching/cache-field-behavior/#handling-pagination state
I was surprised that the first form does not work in the
readField
function passed to a custommerge
function - since apollographql/apollo-client#5722 the options should work the same in bothread
functions andmerge
functions.The use case might be to use the parent object's information, in addition to the field arguments, to figure out whether two objects should be merged or not. (I admit it's probably a bad idea to do that).
It's also useful for basic logging (while debugging) as in the snippet above. Unfortunately, the call just returns
undefined
instead of the entity id.I'm not quite sure whether this should be a bug report against the library, a feature request (as it would be considered a new feature), or a bug report against the documentation.
The text was updated successfully, but these errors were encountered: