【问题标题】:Undefined binding(s) detected when compiling SELECT query编译 SELECT 查询时检测到未定义的绑定
【发布时间】:2019-06-18 20:20:59
【问题描述】:

我正在关注strapi 的教程,但我被困在查询属于餐厅的菜肴的部分。我确定一切都已正确设置,定义了一个(餐厅)到多个(菜肴)关系,但查询不起作用。我已经追踪到实际的查询是:

query {
    restaurant(id: "1") {
    id
    name
    dishes {
      name
      description
    }
  }
}

当我在操场上运行它时会返回一个错误。该查询在我编写时没有显示任何问题,并且不允许我编写如下内容:

query {
    restaurant(where:{id: "1"}) {
    id
    name
    dishes {
      name
      description
    }
  }
}

我的数据库是mysql,两张表是这样的:

mysql> describe dishes;
+-------------+---------------+------+-----+-------------------+-----------------------------+
| Field       | Type          | Null | Key | Default           | Extra                       |
+-------------+---------------+------+-----+-------------------+-----------------------------+
| id          | int(11)       | NO   | PRI | NULL              | auto_increment              |
| name        | varchar(255)  | YES  | MUL | NULL              |                             |
| description | longtext      | YES  |     | NULL              |                             |
| price       | decimal(10,2) | YES  |     | NULL              |                             |
| restaurant  | int(11)       | YES  |     | NULL              |                             |
| created_at  | timestamp     | NO   |     | CURRENT_TIMESTAMP |                             |
| updated_at  | timestamp     | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------------+---------------+------+-----+-------------------+-----------------------------+
7 rows in set (0.00 sec)


mysql> describe restaurants;
+-------------+--------------+------+-----+-------------------+-----------------------------+
| Field       | Type         | Null | Key | Default           | Extra                       |
+-------------+--------------+------+-----+-------------------+-----------------------------+
| id          | int(11)      | NO   | PRI | NULL              | auto_increment              |
| name        | varchar(255) | YES  | MUL | NULL              |                             |
| description | longtext     | YES  |     | NULL              |                             |
| created_at  | timestamp    | NO   |     | CURRENT_TIMESTAMP |                             |
| updated_at  | timestamp    | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------------+--------------+------+-----+-------------------+-----------------------------+
5 rows in set (0.00 sec)

这些表是由strapi自动生成的。

操场上的完整错误是这样的:

{
  "errors": [
    {
      "message": "Undefined binding(s) detected when compiling SELECT query: select `restaurants`.* from `restaurants` where `restaurants`.`id` = ? limit ?",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "restaurant"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Undefined binding(s) detected when compiling SELECT query: select `restaurants`.* from `restaurants` where `restaurants`.`id` = ? limit ?",
            "    at QueryCompiler_MySQL.toSQL (/Users/redqueen/development/deliveroo/server/node_modules/knex/lib/query/compiler.js:85:13)",
            "    at Builder.toSQL (/Users/redqueen/development/deliveroo/server/node_modules/knex/lib/query/builder.js:72:44)",
            "    at /Users/redqueen/development/deliveroo/server/node_modules/knex/lib/runner.js:37:34",
            "From previous event:",
            "    at Runner.run (/Users/redqueen/development/deliveroo/server/node_modules/knex/lib/runner.js:33:30)",
            "    at Builder.Target.then (/Users/redqueen/development/deliveroo/server/node_modules/knex/lib/interface.js:23:43)",
            "    at runCallback (timers.js:705:18)",
            "    at tryOnImmediate (timers.js:676:5)",
            "    at processImmediate (timers.js:658:5)",
            "    at process.topLevelDomainCallback (domain.js:120:23)"
          ]
        }
      }
    }
  ],
  "data":

知道为什么会这样吗?

【问题讨论】:

    标签: graphql knex.js strapi


    【解决方案1】:

    这似乎是 alpha.v20 和 alpha.v21 版本的strapi 的错误。已经发布了一个错误修复来解决它,github上的一个问题线程是here.

    【讨论】:

      猜你喜欢
      • 2017-12-04
      • 2017-12-15
      • 1970-01-01
      • 1970-01-01
      • 2020-05-30
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      • 2017-08-29
      相关资源
      最近更新 更多