After I'm sending a createMessage
mutation in my app, I want to update the local ApolloStore
using updateQueries
.
My setup looks as follows:
const ChatWithAllMessages = graphql(allMessages, {name: 'allMessagesQuery'})(Chat)
export default graphql(createMessage, {
props({ownProps, mutate}) {
return {
createMessageMutation(text, conversationId) {
return mutate({
variables: { text, conversationId },
updateQueries: {
allConversations: (previousState, {mutationResult}) => {
console.log('Chat - did send mutation for allConversationsQuery: ', previousState, mutationResult)
return ...
}
}
})
}
}
}
})(ChatWithAllMessages)
I'm calling the createMessageMutation
in my code like so:
_onSend = () => {
this.props.createMessageMutation(this.state.message, this.props.conversationId)
}
With this setup I would expect the function that I specified in the value for updateQueries
to be executed, however, that doesn't seem to happen (the logging statement is never printed).
For reference, this is what the allConversation
query in the ApolloStore
looks like:
Also, this how it's defined in my JS code:
const findConversations = gql`
query allConversations($customerId: ID!) {
allConversations(filter: {
customer: {
id: $customerId
}
}){
id
updatedAt
slackChannelName
agent {
id
slackUserName
}
messages(last: 1) {
id
text
createdAt
}
}
}
`
Does anyone spot what I'm doing wrong?