在我的应用程序中发送createMessage
突变后,我想ApolloStore
使用updateQueries
.
我的设置如下所示:
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)
我createMessageMutation
在我的代码中这样调用:
_onSend = () => {
this.props.createMessageMutation(this.state.message, this.props.conversationId)
}
有了这个设置,我希望我在值中指定的函数updateQueries
被执行,但是,这似乎没有发生(日志语句从不打印)。
作为参考,这是allConversation
查询中的ApolloStore
样子:
此外,这在我的 JS 代码中是如何定义的:
const findConversations = gql`
query allConversations($customerId: ID!) {
allConversations(filter: {
customer: {
id: $customerId
}
}){
id
updatedAt
slackChannelName
agent {
id
slackUserName
}
messages(last: 1) {
id
text
createdAt
}
}
}
`
有没有人发现我做错了什么?