当我发送一个createMessage
我的应用程序发生突变,我想更新本地ApolloStore
using 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
好像:
![enter image description here](https://i.stack.imgur.com/utYAe.png)
另外,我的 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
}
}
}
`
有人发现我做错了什么吗?