Paginated Queries correctly when multiple concurrent mutations
Consider a ChatGPT-like interface with a list of messages. I'm using paginated queries to fetch the N most recent messages and display them to the user with an option to "Load earlier messages."
When a user edits a message, the conversation restarts from that point. For example, in a chat with 100 messages where the last 20 are displayed due to pagination, editing message #85 would trigger two actions: the backend would delete all messages after #85, and the AI would generate a new response to the edited message. This would result in a chat containing 86 messages.
Currently, my "update message" mutation performs the following:
1. Update the edited message
2. Add a placeholder message for the AI response
3. Trigger (schedule) an action to delete all messages after the edited message and before the placeholder AI message.
4. Trigger (schedule) an action to connect to OpenAI API and incrementally update the placeholder AI message as the response streams in.
My pagination is messed up! As these updates are happening,
usePaginatedQuery keeps getting triggered, and I constantly see a "hit error" saying "InvalidCursor: Tried to run a query starting from a cursor, but it looks like this cursor is from a different query."