Example code for "Delete mutation and update cache" is broken
Philzen opened this issue · 1 comments
Philzen commented
The update-method cannot work, because todo.id is simply not available in that scope. The default way to do that (as far as i could deduct from the apollo docs) would be to destructure delete_todo like this: update(cache, { data: { delete_todo } }) and then grab the id from there.
Otherwise, this tutorial really made my day, because i had two ground-breaking realisations:
- When applying the generated types, as this tutorial page demonstrates, one won't have to worry about changes or typos in the query name (
delete_todos) for destructuring – typescript will enforce the right name - actually, the error on this page led me to another discovery: because i was wondering in what scope
todo.idcould be available for this to work, i tried out what other options could be provided totodoRemove()… and booom: yes, you can supply any option you can give touseMutationthere as well. So it is possible to use information in other callbacks that would otherwise never be available in theuseMutation-scope, for instance show an alert containing the deleted todo-textonCompleted(The project i'm working on cannot return the complete deleted object after the mutation, therefore the deleted items' title was never available in the callback data, so this is a fantastic workaround)
This actually solved a challenge i thought was hardly solvable for me! 🔥
Unless i have overlooked something, i can try to rectify the issue. Kindly advise.
I could also expand the tutorial with my two findings if i find the time.
praveenweb commented