未定义传递给Parser的参数不是有效的GraphQl DocumentNode

发布于 2025-02-07 01:49:59 字数 952 浏览 1 评论 0原文

这是我的clientmutations.js文件。我正在使用 @apollo-client的GQL。 从“@apollo/client”导入{gql};

const DELETE_CLIENT = gql`
  mutation deleteClient($id: ID!) {
    deleteClient(id: $id) {
      id
      name
      email
      phone
    }
  }
`;

这是使用查询的组件。

import { DELETE_CLIENT } from "../mutations/clientMutations";

export default function ClientRow({ client }) {
  const { deleteClient } = useMutation(DELETE_CLIENT, {
    variables: { id: client.id },
  });
  return (
    <tr>
      <td>{client.name}</td>
      <td>{client.email}</td>
      <td>{client.phone}</td>
      <td>
        <button className="btn btn-danger btn-sm" onClick={deleteClient}>
          <FaTrash />
        </button>
      </td>
    </tr>
  );
}

我正在违反不变的侵犯:未定义传递给Parser的论点不是有效的GraphQl DocumentNode。您可能需要使用“ GraphQL-TAG”或其他方法将操作转换为我的浏览器控制台中的文档。

This is my clientMutations.js file. I am using gql from @apollo-client.
import { gql } from "@apollo/client";

const DELETE_CLIENT = gql`
  mutation deleteClient($id: ID!) {
    deleteClient(id: $id) {
      id
      name
      email
      phone
    }
  }
`;

Here is the component that uses the query.

import { DELETE_CLIENT } from "../mutations/clientMutations";

export default function ClientRow({ client }) {
  const { deleteClient } = useMutation(DELETE_CLIENT, {
    variables: { id: client.id },
  });
  return (
    <tr>
      <td>{client.name}</td>
      <td>{client.email}</td>
      <td>{client.phone}</td>
      <td>
        <button className="btn btn-danger btn-sm" onClick={deleteClient}>
          <FaTrash />
        </button>
      </td>
    </tr>
  );
}

i am getting Invariant Violation: Argument of undefined passed to parser was not a valid GraphQL DocumentNode. You may need to use 'graphql-tag' or another method to convert your operation into a document in my browser console.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃颗糖壮壮胆 2025-02-14 01:49:59

我能够通过重新启动反应来解决此问题。我还通过使用破坏对象而不是在此处使用阵列来犯了一个错误:

  const [ deleteClient ] = useMutation(DELETE_CLIENT, {
    variables: { id: client.id },
  });

I was able to solve this by restarting react. I had also made a mistake by using object destructuring rather than using array destructuring here:

  const [ deleteClient ] = useMutation(DELETE_CLIENT, {
    variables: { id: client.id },
  });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文