Skip to content
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

Provide an API to watch fragments #2329

Open
jpvajda opened this issue Jun 24, 2022 · 3 comments
Open

Provide an API to watch fragments #2329

jpvajda opened this issue Jun 24, 2022 · 3 comments
Labels
feature New addition or enhancement to existing solutions

Comments

@jpvajda
Copy link
Contributor

jpvajda commented Jun 24, 2022

Relates to

apollographql/apollo-client#8236
apollographql/apollo-feature-requests#198

Details

This relates to our work in our web Client to offer a useFragment hook, and there has been some interest in this same level of functionality in iOS.

useFragment is a read-only reactive/live binding into the cache, providing an always-up-to-date view of whatever data the cache currently contains for a given fragment.

It makes sense to want to watch just a fragment but it's not possible in iOS at the moment; it looks like our watcher functions are restricted to queries only.

@jpvajda jpvajda added the feature New addition or enhancement to existing solutions label Jun 24, 2022
@jpvajda jpvajda changed the title Provide a UseFragment hook in iOS Provide an API to watch fragments Jun 24, 2022
@jpvajda
Copy link
Contributor Author

jpvajda commented Jul 5, 2022

From a discussion I had with the requester of this feature:

There is sort of a work around where you can create a getFoo(uuid: ID!): Foo query then have the cache know how to lookup that entity even if it came in a list. But would be nice to have it as a first class concept and it seems like it could be possible given things are already effectively stored this way in the normalized cache.

@kroussevrb
Copy link

@jpvajda what do you mean "even if it came in a list". Doesn't cacheKeyForObject = { $0["id"] } suffice if the Foo id is included in both the list query and the getFoo query?

@cerupcat
Copy link

cerupcat commented Jul 1, 2023

I'm curious how to achieve this. I don't quite get the Foo workaround @jpvajda.

I'm trying to observe changes to an array of objects that are modified from a different screen. The objects are a shared fragment.

Screen 1: Query that returns a list of objects
Screen 2: Can add or remove objects
Screen 1: Would like to receive updates when objects are added or removed from Screen 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New addition or enhancement to existing solutions
Projects
None yet
Development

No branches or pull requests

3 participants