【问题标题】:Could not find argument in nested Prisma / GraphQL query在嵌套的 Prisma / GraphQL 查询中找不到参数
【发布时间】:2019-03-23 19:05:53
【问题描述】:

在我的 graphql-yoga 服务器中,我有这样的架构:

type Play {
  id: ID!
  frames: [Frame!]!
}

type Frame {
  id: ID!
  play: Play!
}

query  {
  play(playId: "myid") {
    id
    ### The error occurs when I uncomment these lines:
    # frames {
    #   id
    # }
  }
}

我有查询的解析器:

return await context.prisma.play({ id: args.playId })

我也有关系解析器,例如:

const frames = async (root, args, context) => {
  return await context.prisma.frames({ play: { id: root.id }})
}

当我运行带有注释行的查询时,它按预期执行。当我添加关系时出现错误:

Error: Could not find argument play for type Frame
    at server\node_modules\prisma-client-lib\dist\Client.js:248:31
    at Array.forEach (<anonymous>)
    at server\node_modules\prisma-client-lib\dist\Client.js:234:50
    at Array.reduceRight (<anonymous>)
    at Client.generateSelections (server\node_modules\prisma-client-lib\dist\Client.js:231:32)
    at Client.<anonymous> (server\node_modules\prisma-client-lib\dist\Client.js:87:35)
    at step (server\node_modules\prisma-client-lib\dist\Client.js:47:23)
    at Object.next (server\node_modules\prisma-client-lib\dist\Client.js:28:53)
    at server\node_modules\prisma-client-lib\dist\Client.js:22:71
    at new Promise (<anonymous>)

我正在使用prisma-client-lib@1.18.1graphql-yoga@1.16.2graphql@0.13.0

【问题讨论】:

    标签: graphql prisma


    【解决方案1】:

    事实证明,这个错误出现在解析器中,尽管堆栈跟踪没有帮助。我变了

    const frames = async (root, args, context) => {
      return await context.prisma.frames({ play: { id: root.id }})
    }
    

    const frames = async (root, args, context) => {
      return await context.prisma.frames({ where: { play: { id: args.playId }}})
    }
    

    【讨论】:

    • 这也正是我所遇到的问题——感谢您的回答!
    猜你喜欢
    • 2020-12-31
    • 2021-01-14
    • 2018-06-13
    • 2019-05-08
    • 2021-09-09
    • 1970-01-01
    • 2021-01-29
    • 2020-12-02
    • 1970-01-01
    相关资源
    最近更新 更多