首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Ctx.db.mutation。“updateAccepted”不是函数..突变不是由Prisma产生的

Ctx.db.mutation。“updateAccepted”不是函数..突变不是由Prisma产生的
EN

Stack Overflow用户
提问于 2019-05-23 22:16:00
回答 1查看 176关注 0票数 0

我尝试进行graphql突变,以更新现有数据库中的项目。当我尝试执行这个变异时,我仍然得到了一个错误。

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

我尝试部署我的模式,但没有任何效果..

代码语言:javascript
运行
复制
type Item {
  id: ID! @id
  title: String!
  image: String
  largeImage: String
  price: Int!
  user: User!
  accepted: String!
}

在此之后,我进行了突变:

代码语言:javascript
运行
复制
type Mutation {
  updateAccepted(id: ID!): Item!
}

然后我编写了解析器:

代码语言:javascript
运行
复制
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;
  },

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

代码语言:javascript
运行
复制
{
  "data": null,
  "errors": [
    {
      "message": "ctx.db.mutation.updateAccepted is not a function",
      "locations": [
        {
          "line": 10,
          "column": 3
        }
      ],
      "path": [
        "updateAccepted"
      ]
    }
  ]
}

有点笨拙的自动取款机,请帮助有需要的开发人员:)

EN

回答 1

Stack Overflow用户

发布于 2019-05-24 23:32:35

问题解决了。问题是我必须调用updateItem而不是updateAccepted。突变在Item类型上。不是accepted..

代码语言:javascript
运行
复制
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
    );
  },

快乐的日子

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56277236

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档