You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After some painful debugging, I noticed that the incubating cache does not emit data on watched queries when writing data using writeOperation, even when disabling all paging support. The same code seems to work when switched back to the production Apollo cache dependency.
I added an update button that should increment all stars by one. It does it successfully, but the data is not refreshed on the screen (you can see the updated data when you restart the app after it fetches the cache).
val data = apolloClient.apolloStore.readOperation(RepositoryListQuery())
val updatedEdges = data.organization?.repositories?.edges?.map { edge ->
edge?.let { e ->
e.copy(
node = e.node?.copy(
repositoryFields = e.node.repositoryFields.copy(
stargazers = e.node.repositoryFields.stargazers.copy(
totalCount = e.node.repositoryFields.stargazers.totalCount +1
)
)
)
)
}
}
val updatedData =
data.copy(organization = data.organization?.copy(repositories = data.organization.repositories.copy(edges = updatedEdges)))
apolloClient.apolloStore.writeOperation(RepositoryListQuery(), updatedData)
The text was updated successfully, but these errors were encountered:
Many thanks for the reproducer 🙏 . This has indeed been a bit of an API challenge (see apollographql/apollo-kotlin#5971) as writing the store is usually a synchronous operation but publishing needs to suspend to wait for possible (slow) consumers. To keep concerns separated, it's 2 APIs in the incubating cache:
writeOperation() (non-suspend)
publish() (suspend)
In your example, you can do something like below:
val keys = apolloClient.apolloStore.writeOperation(RepositoryListQuery(), updatedData)
apolloClient.apolloStore.publish(keys)
After some painful debugging, I noticed that the incubating cache does not emit data on watched queries when writing data using writeOperation, even when disabling all paging support. The same code seems to work when switched back to the production Apollo cache dependency.
I put up a quick sample here:
https://github.com/cvb941/apollo-kotlin-normalized-cache-incubating/tree/main/samples/cache-watching-test
I added an update button that should increment all stars by one. It does it successfully, but the data is not refreshed on the screen (you can see the updated data when you restart the app after it fetches the cache).
The text was updated successfully, but these errors were encountered: