Can OptimisticEffect work this way ?
Let’s say I have two objects “A” and “B”.
Object A has ONE TO MANY relation with Object B.
Now, I use “useFindManyRecords” for Object A and in its query fields I fetch Object B items as well. With this “useUpdateManyRecord” and other CRUD hooks for this same Object A works fine and optimistic effect is running properly as well.
But now If I run “useDeleteOneRecord” for Object B then would the OptimisticEffect work as expected ? In my implementation it doesn’t seem to work.
9 Replies
Hi @D_Gamer, I'm missing some details in your case, could you be more specific and provide a way ti reproduce the issue (maybe with screenshots) ? OptimisticEffect should work in your case theoretically but we might have a bug, we know that a few edge cases are not properly covered
Hey @charles , try to picture this
There is a rolePermission System Object that I have created. I fetch records for this object using
useFindManyRecords()
like this...
This is the ROLE_PERMISSION_QUERY_KEY object,
Now, as per the data I am requesting, it will consists RoleAssignment objects,
now at somepoint in flow, I am using useCreateOneRecord()
to create new RoleAssignment for this RolePermission, and I expect that this should be reflected in my useFindManyRecords()
records
object and which should result in state update and trigger rerender.
This is how I am creating a new RoleAssignment,
I think I will have to use
useCreateOneRecordMutation
, make api call manually and handle cache update myself.
Hi @charles , let me know your thoughts on this.(I'm trying to reproduce locally)
Let me know if you need any more info on this.
Okay, back to it!
@D_Gamer, I've investigated your issue
So in a nutshell, it should work but we have bugs with optimistic rendering and relations. I think I know where it comes from and will tentatively make a fix for v0.11. What you can do for now, is to manually trigger optimistic rendering. Take a look at usePersistViewSortRecords for example, you could use:
- apolloClient.mutate with update callback directly
- triggerUpdateRecordOptimisticEffect with a record
- there is a whole toolbox to interact with the cache: getRecordFromCache, getRecordConnectionFromRecords, ...
If you haven't installed it, install the Apollo Chrome extension it helps a lot
Note that we are 95% sure about the technical fundations of the optimistic rendering but the hook APIs in the code are going to slightly move in the upcoming weeks to ensure a good developer experience (the developer should not have to worry about optimistic rendering at all)
I'll keep you posted on the fix
Alrighty ! Thanks man. 🙃
We have updated optimistic in v0.10.4 (we have changed a bunch of things: depth is deprecated and queryFields ==> recordGqlFields)
If you want to update your logic and you are still facing bug, I'm interested into troubleshooting issues with you
Sure! Will try again and let you know.