未捕获的错误:react-apollo仅根据HOC支持查询,订阅或突变

nbu*_*urk 4 javascript apollo reactjs graphql react-apollo

我正在尝试使用封装Chat两个查询和一个突变的组件compose

但是,控制台中仍然出现以下错误:

未捕获的错误: react-apollo每个HOC仅支持查询,订阅或突变。[object Object]有2个查询,0个订阅和0个突变。您可以使用' compose'将多种操作类型连接到一个组件

这是我的查询和导出语句:

// 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)
Run Code Online (Sandbox Code Playgroud)

显然,问题出在findConversations查询上。如果我将其注释掉,则不会得到该错误,并且组件会正确加载:

// this works
export default compose(
  // graphql(findConversations, {name: 'findConversationsQuery'}),
  graphql(allMessages, {name: 'allMessagesQuery'}),
  graphql(createMessage, {name : 'createMessageMutation'})
)(Chat)
Run Code Online (Sandbox Code Playgroud)

谁能告诉我我所缺少的吗?

顺便说一句,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),
  })

}
Run Code Online (Sandbox Code Playgroud)

hel*_*fer 5

findConversationsQuery实际上是两个查询。这个:

query allConversations($customerId: ID!) {
    allConversations(filter: {
      customerId: $customerId
    })
} 
Run Code Online (Sandbox Code Playgroud)

还有这个:

{
    id
}
Run Code Online (Sandbox Code Playgroud)

整个查询需要包含在一对左右的括号之间。

我认为您的意思是:

query allConversations($customerId: ID!) {
    allConversations(filter: { customerId: $customerId }){
        id
    }
} 
Run Code Online (Sandbox Code Playgroud)