【问题标题】:Ctx.db.mutation."updateAccepted" is not a function.. Mutation isn't generated by PrismaCtx.db.mutation."updateAccepted" 不是函数.. Prisma 不会生成突变
【发布时间】:2019-10-10 03:31:51
【问题描述】:

我尝试制作一个 graphql 突变来更新我现有数据库中的项目。当我尝试执行此突变时,仍然出现错误。

我在项目中添加了“接受”:

我尝试部署我的架构,但没有任何影响..

type Item {
  id: ID! @id
  title: String!
  image: String
  largeImage: String
  price: Int!
  user: User!
  accepted: String!
}

在这之后我做了突变:

type Mutation {
  updateAccepted(id: ID!): Item!
}

然后我写了解析器:

async updateAccepted(parent, args, ctx, info) {
    // 1. Check if the person is logged in
    const { userId } = ctx.request;
    if (!userId) {
      throw new Error('You must be signed in');
    }
    // 2. find the item
    const item = await ctx.db.mutation.updateAccepted(
      {
        where: { id: args.id },
        data: {
          accepted: 1
        }
      },
      info
    );

    // 3. Return the item
    return item;
  },

当我在操场上执行这个函数时,我得到了这个错误

{
  "data": null,
  "errors": [
    {
      "message": "ctx.db.mutation.updateAccepted is not a function",
      "locations": [
        {
          "line": 10,
          "column": 3
        }
      ],
      "path": [
        "updateAccepted"
      ]
    }
  ]
}

有点笨的atm,请帮助有需要的开发人员:)

【问题讨论】:

  • 这似乎不是您的 graphql 定义或 prisma 的问题,而是您的数据库驱动程序。你用什么来查询数据库?
  • GraphQL Yoga Server,我基于 Wes Bos 的 Advance React GraphQL 课程构建我的网站

标签: reactjs graphql next.js prisma prisma-graphql


【解决方案1】:

问题已解决。问题是我不得不打电话给updateItem 而不是updateAccepted。突变类型为Item... 而不是accepted..

async updateAccepted(parent, args, ctx, info) {
    const { id, accepted } = args;
    // 1. Check if the person is logged in
    const { userId } = ctx.request;
    if (!userId) {
      throw new Error('You must be signed in');
    }
    // 2. find the item
    return ctx.db.mutation.updateItem(
      {
        data: { accepted },
        where: { id: args.id }
      },
      info
    );
  },

快乐的日子

【讨论】:

    猜你喜欢
    • 2021-07-02
    • 2019-06-11
    • 2021-02-09
    • 2020-10-31
    • 2019-06-18
    • 2022-08-22
    • 2020-08-16
    • 2020-10-09
    • 2019-09-09
    相关资源
    最近更新 更多