【问题标题】:Postgraphile error while trying to open UI尝试打开 UI 时出现 Postgraphile 错误
【发布时间】:2021-06-03 09:18:29
【问题描述】:

当我尝试打开 postgraphile UI 时,它不起作用。我收到以下错误。

构建初始架构时出现严重错误。退出 因为没有设置retryOnInitFail

错误:连接意外终止
在连接处。 (D:\cars-assignment\node_modules\pg\lib\client.js:132:73)
在 Object.onceWrapper (events.js:421:28)
在 Connection.emit (events.js:315:20)
在套接字。 (D:\cars-assignment\node_modules\pg\lib\connection.js:108:12)
在 Socket.emit (events.js:327:22)
在 endReadableNT (_stream_readable.js:1201:12)
在 processTicksAndRejections (internal/process/task_queues.js:84:21)

我正在使用以下命令 npx postgraphile -c postgres://username:SECRET@localhost:5000/db

如何解决这个问题?

【问题讨论】:

    标签: graphql nestjs postgraphile


    【解决方案1】:

    我认为错误输出比@deluxan 显示的更多。至少对我来说有。我认为问题在于 postgraphile 忽略了连接字符串中指定的端口。首先,我在端口 5555 上公开的 Docker 容器中运行 PostgreSQL。

    17502bafdf52        exspda_postgis                   "docker-entrypoint.s…"   2 months ago        Up 5 minutes        0.0.0.0:5555->5432/tcp          exspda_postgis
    

    然后当我尝试通过 Docker 运行 Postgraphile...

    $ docker run --init -p 5000:5000 graphile/postgraphile --connection postgres://hippo:mypassword@localhost:5555/first_geo --schema public --watch
    

    ...完整的输出是:

    PostGraphile v4.12.1 server listening on port 5000 ?
    
      ‣ GraphQL API:         http://0.0.0.0:5000/graphql
      ‣ GraphiQL GUI/IDE:    http://0.0.0.0:5000/graphiql (RECOMMENDATION: add '--enhance-graphiql')
      ‣ Postgres connection: postgres://hippo:[SECRET]@localhost/first_geo (watching)
      ‣ Postgres schema(s):  public
      ‣ Documentation:       https://graphile.org/postgraphile/introduction/
      ‣ Node.js version:     v12.22.1 on linux x64
      ‣ Join Storyscript in supporting PostGraphile development: https://graphile.org/sponsor/
    
    * * *
    
    A serious error occurred when building the initial schema. Exiting because `retryOnInitFail` is not set. Error details:
    
    Error: connect ECONNREFUSED 127.0.0.1:5432
        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)
    

    输出Postgres connection: postgres://hippo:[SECRET]@localhost/first_geo 不包括我在连接字符串中指定的端口。实际错误似乎还表明我指定的端口未使用:Error: connect ECONNREFUSED 127.0.0.1:5432。当我指定 5555 时,它正在尝试使用端口 5432。我怀疑这与@deluxan 经历的相同。端口 5432 是否在 postgraphile 中硬编码?如何修复识别用户提供的连接字符串中指定的端口?

    请注意,我是 Postgraphile 的新手,因此对于愚蠢(即对其他人来说显而易见)的疏忽和错误,我深表歉意!

    【讨论】:

      【解决方案2】:

      这是 Node 和 Postgres 之间的连接错误。尝试直接连接pg模块;它应该以同样的方式失败,您可以从那里继续调试:

      const { Pool } = require('pg');
      
      const pool = new Pool({
        connectionString: "postgres://username:SECRET@localhost:5000/db"
      });
      
      async function main() {
        await pool.query('select 1');
        pool.end();
        console.log('All good.');
      }
      
      main().catch(e => {
        console.error(e);
        process.exit(1);
      });
      

      我怀疑 :5000 是错误的,因为这是 PostGraphile 默认尝试侦听的端口,而 postgres 默认使用 :5432。

      【讨论】:

        猜你喜欢
        • 2017-09-28
        • 1970-01-01
        • 1970-01-01
        • 2012-02-29
        • 2023-01-13
        • 2020-11-17
        • 2018-09-27
        • 2012-08-09
        • 2012-06-22
        相关资源
        最近更新 更多