简体   繁体   English

React-Apollo 错误:“……仅支持每个 HOC 的查询、订阅或突变”

[英]React-Apollo error: “…only supports a query, subscription, or a mutation per HOC”

I am trying to create two separate mutations in this format:我正在尝试以这种格式创建两个单独的突变:

import gql from 'graphql-tag';

const MUTATION = gql`
  mutation setItem($item:String!) {
    setItem(item:$item)
  },
  mutation setAnotherItem($setAnotherItem:Bool) {
    setAnotherItem(setAnotherItem:$setAnotherItem)
  }
`;

But I am getting this error:但我收到此错误:

Invariant Violation: react-apollo only supports a query, subscription, or a mutation per HOC. [object Object] had 0 queries, 0 subscriptions and 2 mutations. You can use 'compose' to join multiple operation types to a component

What is the proper way to structure this so that both mutations are usable?什么是构造它以使两个突变都可用的正确方法?

You need to type just once mutation and nest inside the (mutation) fields:您只需键入一次mutation并嵌套在 (mutation) 字段中:

import gql from 'graphql-tag';

const MUTATION = gql`
  mutation MyMutation ($item: String, $setAnotherItem: Book) {
    setItem(item: $item) { ...}
    setAnotherItem(setAnotherItem: $setAnotherItem) {...}
  }
`;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM