首页 > 解决方案 > Ctx.db.mutation."updateAccepted" 不是函数.. Prisma 不会生成突变

问题描述

我尝试制作一个 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,请帮助有需要的开发人员:)

标签: reactjsgraphqlnext.jsprismaprisma-graphql

解决方案


问题解决了。问题是我不得不打电话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
    );
  },

快乐的时光


推荐阅读