createMessage
돌연변이를 앱에 전송 한 후 ApolloStore
을 updateQueries
으로 업데이트하려고합니다.GraphQL 돌연변이가 Apollo 클라이언트와 작동하지 않는 후 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
이 실행될 수는 있지만 발생하지 않는 것입니다 (로깅 문은 절대로 인쇄되지 않습니다).
const findConversations = gql`
query allConversations($customerId: ID!) {
allConversations(filter: {
customer: {
id: $customerId
}
}){
id
updatedAt
slackChannelName
agent {
id
slackUserName
}
messages(last: 1) {
id
text
createdAt
}
}
}
`
사람이 무엇을 발견 하는가 :
는, 이것이이 내 JS 코드에 정의 된 방법은 다음과 같습니다 참고로
,이 같은 ApolloStore
의 allConversation
쿼리 모습입니다 내가 잘못하고있어?
> updateQuery 기능은 변형에 대한 뷰가 쿼리에 대한 참조를 보유 할 때만 호출됩니다. 해당 진술에 대한 참조가 있습니까? – marktani
아폴로의 문서에 이렇게 쓰여진 것은 아닙니다. [updateQueries definition] (http://dev.apollodata.com/react/cache-updates.html#updateQueries)을 통해 읽으면 "CommentsPage 구성 요소가 호출 할 수있는 함수 prop를 통해이 변형을 노출합니다."라는 두 개의 문이 있습니다. 및 "주석 페이지 자체는 다음 쿼리로 렌더링됩니다." 그래서 쿼리는 구성 요소의 소품에 있어야한다고 생각했습니다. –
[이 댓글] (https://github.com/apollographql/apollo-client/issues/1129#issuecomment-270677147)을 참고하면 동작이 버그 인 것 같습니다. 비록 내가 현재의 합의에 관해 명확하지 않더라도. – marktani