createMessage
突然変異をアプリケーションに送信した後、ローカルApolloStore
をupdateQueries
を使用して更新したいとします。GraphQL突然変異がApolloクライアントで機能しなくなった後のupdateQuery
次のように私のセットアップが見えます:
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
が実行されると、それは起こらないようです(ロギングステートメントは決して印刷されません)。
、それは私の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
}
}
}
`
誰が何を見つけたん参考のために、これはApolloStore
でallConversation
クエリがどのように見えるか
です私は間違っている?
> updateQuery機能は、突然変異のビューがクエリへの参照を保持している場合にのみ呼び出されます。 あなたはその声明のリファレンスを持っていますか? – marktani
これはapolloのドキュメントに直接書かれていません。 [updateQueries定義](http://dev.apollodata.com/react/cache-updates.html#updateQueries)を読むと、「CommentsPageコンポーネントが呼び出すことができる関数propを使ってこの突然変異を公開する」という2つのステートメントがあります。 「コメントページ自体は次のクエリで表示されます」だから私はクエリがコンポーネントの小道具にあると思った。 –
[このコメント](https://github.com/apollographql/apollo-client/issues/1129#issuecomment-270677147)を参照すると、動作がバグであるように聞こえます。私はここでの現在の合意についてはっきりしていないが。 – marktani