4

When I try to open postgraphile UI it's not working. I'm getting the following error.

A serious error occurred when building the initial schema. Exiting because retryOnInitFail is not set.

Error: Connection terminated unexpectedly
at Connection. (D:\cars-assignment\node_modules\pg\lib\client.js:132:73)
at Object.onceWrapper (events.js:421:28)
at Connection.emit (events.js:315:20)
at Socket. (D:\cars-assignment\node_modules\pg\lib\connection.js:108:12)
at Socket.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1201:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)

I'm using the following command npx postgraphile -c postgres://username:SECRET@localhost:5000/db

How to resolve this issue?

deluxan
  • 372
  • 1
  • 5
  • 22

2 Answers2

1

I think there is more to the error output than @deluxan is showing. At least there is for me. I think the problem is that postgraphile is ignoring the port specified in the connection string. First, I have PostgreSQL running in a Docker container exposed on port 5555.

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

Then when I attempt to run Postgraphile via Docker...

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

...the full output is:

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)

The output Postgres connection: postgres://hippo:[SECRET]@localhost/first_geo does not include the port I specified in the connection string. The actual error also appears to show that the port I specified is not used: Error: connect ECONNREFUSED 127.0.0.1:5432. It is trying to use port 5432 when I specified 5555. I suspect this is the same thing that @deluxan experienced. Is port 5432 hard-coded in postgraphile? How can it be fixed to recognize the port specified in the user-provided connection string?

Please note that I am brand new to Postgraphile so my apologies for silly (i.e., obvious to others) oversights and mistakes!

Nate
  • 11
  • 2
0

This is a connection error between Node and Postgres. Try connecting with the pg module directly; it should fail in the same way and you can continue debugging from there:

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);
});

I suspect the :5000 is wrong since this is the port PostGraphile tries to listen on by default whereas postgres uses :5432 by default.

Benjie
  • 7,701
  • 5
  • 29
  • 44