【问题标题】:I'm getting that query is not a function我得到那个查询不是一个函数
【发布时间】:2019-11-13 11:32:57
【问题描述】:

编辑01

我正在运行命令prisma deploy,当命令执行完毕时,所有查询都在文件src/generated/graphql-schema/prisma.graphql 中可见,除了查询listProdutos 没有出现在文件中。

是这样配置的:

解析器/Query.js

function listProdutos (_, args, ctx, info) {
  const userId = getUserId(ctx) 
  return ctx.db.query.produtos({
    where: {
      OR: [
        {
          user: {
            id: userId
          }
        }
      ]
    }
  }, info)
}

schema.graphql

type Query {
  listProdutos: [ Produto! ]!
}

我有以下错误:

{
  "data": null,
  "errors": [
    {
      "message": "ctx.db.query.produtos is not a function",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "listProdutos"
      ]
    }
  ]
}

如果需要,我将项目放入 git:

https://github.com/Denis-String/lavacar-back

【问题讨论】:

    标签: node.js graphql prisma


    【解决方案1】:

    您的查询 listProdutos 是您自己的 schema.graphql 查询名称,但不是 prisma 生成的查询。您的解析器应如下所示:

    function listProdutos (_, args, ctx, info) {
      const userId = getUserId(ctx) 
      return ctx.db.query.produtos({
        where: {
          OR: [
            {
              user: {
                id: userId
              }
            }
          ]
        }
      }, info)
    }
    

    【讨论】:

    • 我一直收到同样的错误,你会有另一个想法,没有创建突变或查询,我正在做的所有新功能都返回这个错误
    【解决方案2】:

    这就是为我解决问题的方法:

    ctx.db.produtos
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多