I have a message list thread that is being called with a request GET_THREAD_MESSAGES
. This request is paginated, and depending on whether the user saw the stream before or could not load the first page, last page or only new messages. (i.e. any of first/after/before/last
can be passed with any values)
thread(id: "asdf") {
messageConnection(after: $after, first: $first, before: $before, last: $last) {
edges {
cursor
node { ...messageInfo }
}
}
}
Now I have a mutation sendMessage
that I cause, and then in the method of update
this mutation. I want to optimistically add this sent message to thread messages for a more convenient UX. Without pagination, I know that I would do something like:
const data = store.readQuery({
query: GET_THREAD_MESSAGES,
variables: { id: message.threadId }
})
data.messageConnection.edges.push(newMessageEdge);
store.writeQuery({
query: GET_THREAD_MESSAGES,
variables: { id: message.threadId },
data,
})
, , store.readQuery
: " messageConnection
", messageConnection({ after: 'jfds1223asdhfl', first: 50, before: null, last: null })
. Apollo docs , @connection
, . , - :
thread(id: "asdf") {
messageConnection(...) @connection(key: "messageConnection") {
edges {
cursor
node { ...messageInfo }
}
}
}
, , , , , "Missing field cursor in { node: { id: '...', timestamp: '...'"
, , , , , a MessageConnectionEdge
, node , , .
Apollo node , ? , ?