Incremental update example question
createTodo, which:1. Calls
todosCollection.insert.2. The
onInsert funtion returns { refetch: false }, which means the optimistic update is immediately rolled back and the UI will not show the new state.3.
api.createTodo is called and the todo is created on the server4.
writeDelete is called and errors out since the item with id: tempId was never added to the store.The todo has been created on the server, but the UI is left in an error state.
Alternatively, if in the
onInsert you call todosCollection.utils.writeInsert(transaction.mutations[0].changes) with the tempId, it will succeed, but then if there is an error actually saving it to the server then the change will never be rolled back unless you also add a writeDelete(tempId) in the catch.Full example: github
What is the right pattern to use?