Ali Madooei
CCConvex Community
•Created by Ali Madooei on 12/22/2024 in #support-community
Paginated Queries correctly when multiple concurrent mutations
I need help implementing Paginated Queries correctly when multiple concurrent mutations (create, delete, and update operations) affect the record count and pagination cursor.
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."14 replies
CCConvex Community
•Created by Ali Madooei on 12/2/2024 in #support-community
Internal queries/mutations/actions vs helper functions
Hi everyone! I'm trying to understand the difference between internal queries/mutations/actions and regular helper functions. I'm going to write down my thoughts here, in a contrived example., and I hope you can help me understand it better. Thanks!
5 replies