查询 returns 错误时,React Admin parseResponse 不会触发

React Admin parseResponse doesn't trigger when query returns error

我正在使用 React Admin 和 ra-data-graphQl,当我更新我的 UserEdit 组件中的某些内容时一切正常,但是,当我需要处理来自 API 的错误消息时,我不不知道从哪里抓到的。

这是我的更新查询:

case 'UPDATE': {
  const updateParams = { ...params };

  return {
    query: gql`mutation updateUser($id: ID!, $data: UpdateUser!) {
                    data: updateUser(id: $id,input:$data) {
                        ${buildFieldsGraphQL(updateFields)}
                    }
                }`,

    variables: {
      ...updateParams,
      id: updateParams.data.uuid,
      data: {
        ...updateParams.data,
      },
    },
    parseResponse: (response) => {
      console.log('tr response: ', response);
    },
  };
}

当API returns出错时,它永远不会到达console.log。

我在此处搜索带有选项的列表 (https://github.com/marmelab/react-admin/tree/master/packages/ra-data-graphql#options) 搜索类似“parseError”的内容,但我没有找到类似的内容。

我需要捕获错误并在 UserEdit 表单中显示一条消息。

阅读我在这个 post 中分享的 link,它是这样说的:

but must return an object matching the options of the ApolloClient query method with an additional parseResponse function.

我知道我应该去“查询”一词中的link检查是否有类似“parserError”的东西,但是link坏了:

https://www.apollographql.com/docs/react/reference/index.html#ApolloClient.query

有什么帮助吗?

好的,它更容易。通过添加 onFailure 函数我可以处理错误。