Uncaught Error: react-apollo only supports a query, subscription, or a mutation per HOC
Uncaught Error: react-apollo only supports a query, subscription, or a mutation per HOC
我正在尝试使用 compose
.
将我的 Chat
组件包含两个查询和一个变更
但是,我仍然在控制台中收到以下错误:
Uncaught Error: react-apollo
only supports a query, subscription, or a mutation per HOC. [object Object]
had 2 queries, 0 subscriptions and 0 mutations. You can use 'compose
' to join multiple operation types to a component
这是我的查询和导出语句:
// this query seems to cause the issue
const findConversations = gql`
query allConversations($customerId: ID!) {
allConversations(filter: {
customerId: $customerId
})
} {
id
}
`
const createMessage = gql`
mutation createMessage($text: String!, $conversationId: ID!) {
createMessage(text: $text, conversationId: $conversationId) {
id
text
}
}
`
const allMessages = gql`
query allMessages($conversationId: ID!) {
allMessages(filter: {
conversation: {
id: $conversationId
}
})
{
text
createdAt
}
}
`
export default compose(
graphql(findConversations, {name: 'findConversationsQuery'}),
graphql(allMessages, {name: 'allMessagesQuery'}),
graphql(createMessage, {name : 'createMessageMutation'})
)(Chat)
显然,问题出在 findConversations
查询上。如果我将其注释掉,我不会收到错误并且组件会正确加载:
// this works
export default compose(
// graphql(findConversations, {name: 'findConversationsQuery'}),
graphql(allMessages, {name: 'allMessagesQuery'}),
graphql(createMessage, {name : 'createMessageMutation'})
)(Chat)
谁能告诉我我错过了什么?
顺便说一下,我还在 allMessagesQuery
上设置了订阅,以防相关:
componentDidMount() {
this.newMessageSubscription = this.props.allMessagesQuery.subscribeToMore({
document: gql`
subscription {
createMessage(filter: {
conversation: {
id: "${this.props.conversationId}"
}
}) {
text
createdAt
}
}
`,
updateQuery: (previousState, {subscriptionData}) => {
...
},
onError: (err) => console.error(err),
})
}
你的findConversationsQuery
实际上是两个查询。这个:
query allConversations($customerId: ID!) {
allConversations(filter: {
customerId: $customerId
})
}
还有这个:
{
id
}
整个查询需要用一对左右括号括起来。
我想你想写的是:
query allConversations($customerId: ID!) {
allConversations(filter: { customerId: $customerId }){
id
}
}
我正在尝试使用 compose
.
Chat
组件包含两个查询和一个变更
但是,我仍然在控制台中收到以下错误:
Uncaught Error:
react-apollo
only supports a query, subscription, or a mutation per HOC.[object Object]
had 2 queries, 0 subscriptions and 0 mutations. You can use 'compose
' to join multiple operation types to a component
这是我的查询和导出语句:
// this query seems to cause the issue
const findConversations = gql`
query allConversations($customerId: ID!) {
allConversations(filter: {
customerId: $customerId
})
} {
id
}
`
const createMessage = gql`
mutation createMessage($text: String!, $conversationId: ID!) {
createMessage(text: $text, conversationId: $conversationId) {
id
text
}
}
`
const allMessages = gql`
query allMessages($conversationId: ID!) {
allMessages(filter: {
conversation: {
id: $conversationId
}
})
{
text
createdAt
}
}
`
export default compose(
graphql(findConversations, {name: 'findConversationsQuery'}),
graphql(allMessages, {name: 'allMessagesQuery'}),
graphql(createMessage, {name : 'createMessageMutation'})
)(Chat)
显然,问题出在 findConversations
查询上。如果我将其注释掉,我不会收到错误并且组件会正确加载:
// this works
export default compose(
// graphql(findConversations, {name: 'findConversationsQuery'}),
graphql(allMessages, {name: 'allMessagesQuery'}),
graphql(createMessage, {name : 'createMessageMutation'})
)(Chat)
谁能告诉我我错过了什么?
顺便说一下,我还在 allMessagesQuery
上设置了订阅,以防相关:
componentDidMount() {
this.newMessageSubscription = this.props.allMessagesQuery.subscribeToMore({
document: gql`
subscription {
createMessage(filter: {
conversation: {
id: "${this.props.conversationId}"
}
}) {
text
createdAt
}
}
`,
updateQuery: (previousState, {subscriptionData}) => {
...
},
onError: (err) => console.error(err),
})
}
你的findConversationsQuery
实际上是两个查询。这个:
query allConversations($customerId: ID!) {
allConversations(filter: {
customerId: $customerId
})
}
还有这个:
{
id
}
整个查询需要用一对左右括号括起来。
我想你想写的是:
query allConversations($customerId: ID!) {
allConversations(filter: { customerId: $customerId }){
id
}
}