【问题标题】:Prisma: use count inside a mutation resolverPrisma:在突变解析器中使用计数
【发布时间】:2019-06-13 13:22:36
【问题描述】:

我有一个突变createPet,如果用户已经创建了 5 个宠物,我希望它抛出一个错误。 我在想这样的事情会起作用,但它不会:

  const petsCount = await db.pets({
    where: { owner: user.id },
  }).count();

我也没有在文档中找到任何内容

【问题讨论】:

    标签: node.js graphql graphql-js prisma-graphql


    【解决方案1】:

    要检索计数,您可以使用聚合:

    const petsCount = await prisma
      .petsConnection({where: {owner: user.id}})
      .aggregate()
      .count()
    

    来源:documentation

    【讨论】:

      猜你喜欢
      • 2019-12-12
      • 2019-06-19
      • 2019-06-18
      • 2019-09-13
      • 2023-03-07
      • 1970-01-01
      • 2019-09-09
      • 2020-02-03
      • 2018-11-19
      相关资源
      最近更新 更多