不知道为什么我的突变无法正常工作。 GrpahQL Apollo NodeJS

时间:2019-05-19 23:52:24

标签: reactjs graphql apollo react-hooks graphiql

我触发此突变时出现错误,不确定原因。

文档:

export const IMPORT_INFO_MUTATION = gql`
  mutation ImportPolicy($data: ImportPolicyInput!) {
    importPolicy(data:$data)
    {
      _id
    }

}

所以变量是:

type ImportPolicyMutationVariables = {
  data: ImportPolicyInput
}

和ImportPolicyInput为:

type ImportPolicyInput = {
  jsonData: Scalars['JSON']
}

` 因此,这是一个名为data的对象,其字段名为jsonData,它也是JSON。

在我的客户端中调用它时:

    useImportPolicyMutation({
      variables: {
        data: {
          jsonData: JSON.parse(stringifiedObj)
        }
      },
    })

我得到一个错误:

Invalid hook call. Hooks can only be called inside of the body of a function 
component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app

我不明白为什么。当我在Graphiql中运行它时,效果很好。我这样运行:

mutation ImportPolicy ($data:ImportPolicyInput!) {
  importPolicy(data: $data) {
    _id
  }
}

以及查询变量中:

{
  "data": {
    "jsonData": {} // Really big obj here
  }
}

0 个答案:

没有答案