graphile / gatsby-source-pg

PostgreSQL source for Gatsby, powered by PostGraphile
36 stars 15 forks source link

Connecting to Heroku #23

Open tyronen opened 4 years ago

tyronen commented 4 years ago

Summary

I'd like to connect to a Postgres instance running in Heroku.

Additional context

I use Heroku's DATABASE_URL environment variable, with the suffix ?ssl=1 in my connectionString. When I run gatsby develop I get this error:

[client] success onPreBootstrap - 0.015s
[client] success createSchemaCustomization - 0.006s
[client]
[client]  ERROR #11321  PLUGIN
[client]
[client] "gatsby-source-pg" threw an error while running the sourceNodes lifecycle:
[client]
[client] self signed certificate
[client]
[client]
[client]
[client]   Error: self signed certificate
[client]
[client]   - From previous event:
[client]
[client]   - api-runner-node.js:460 Promise.catch.decorateEvent.pluginName
[client]     [yl]/[gatsby]/src/utils/api-runner-node.js:460:9
[client]
[client]   - From previous event:
[client]
[client]   - api-runner-node.js:459
[client]     [yl]/[gatsby]/src/utils/api-runner-node.js:459:14
[client]
[client]   - timers.js:456 processImmediate
[client]     internal/timers.js:456:21
[client]
[client]   - From previous event:
[client]
[client]   - api-runner-node.js:451
[client]     [yl]/[gatsby]/src/utils/api-runner-node.js:451:13
[client]
[client]   - From previous event:
[client]
[client]   - api-runner-node.js:367 module.exports
[client]     [yl]/[gatsby]/src/utils/api-runner-node.js:367:3
[client]
[client]   - source-nodes.ts:97 _default
[client]     [yl]/[gatsby]/src/utils/source-nodes.ts:97:9
[client]
[client]   - source-nodes.ts:24 sourceNodes
[client]     [yl]/[gatsby]/src/services/source-nodes.ts:24:9
[client]
[client]   - interpreter.js:707 Interpreter.exec
[client]     [yl]/[xstate]/lib/interpreter.js:707:27
[client]
[client]   - interpreter.js:210 Interpreter.execute
[client]     [yl]/[xstate]/lib/interpreter.js:210:22
[client]
[client]   - interpreter.js:230 Interpreter.update
[client]     [yl]/[xstate]/lib/interpreter.js:230:18
[client]
[client]   - interpreter.js:131
[client]     [yl]/[xstate]/lib/interpreter.js:131:23
[client]
[client]   - scheduler.js:60 Scheduler.process
[client]     [yl]/[xstate]/lib/scheduler.js:60:13
[client]
[client]   - scheduler.js:44 Scheduler.schedule
[client]     [yl]/[xstate]/lib/scheduler.js:44:14
[client]
[client]   - interpreter.js:127 Interpreter.send
[client]     [yl]/[xstate]/lib/interpreter.js:127:29
[client]
[client]   - interpreter.js:825 actor.id
[client]     [yl]/[xstate]/lib/interpreter.js:825:23
[client]
[client]
[client] warn The gatsby-source-pg plugin has generated no Gatsby nodes. Do you need it?
benjie commented 4 years ago

For more information on this error, see: https://github.com/brianc/node-postgres/issues/2009

Indicating the right SSL certificate using the ?sslrootcert=... option should work, but it's kind of finicky to get it to work. I had success on Node 12 doing this, but on Node 14 not so much.

Since we're using a connection string, we can't just add rejectUnauthorized: false (though you could try it with ?rejectUnauthorized=0 or similar, I suppose).

I recently raised this PR against pg-connection-string to allow for parsing ?sslmode=no-verify, but I'm not sure if it's released yet: https://github.com/brianc/node-postgres/pull/2345

Another option is to disable Node's TLS validation; e.g.:

process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

https://stackoverflow.com/a/21961005/141284

Ultimately this is an issue between the pg module, your Node version, your server's trusted SSL certificates, and your database server. gatsby-source-pg has very little say in the matter.