Node version: 8.2.1
Dependencies:
"dependencies": {
"express": "^4.15.4",
"jsonwebtoken": "^7.4.2",
"pg": "^7.1.2",
"postgraphql": "next"
},
"devDependencies": {
"nodemon": "^1.11.0"
}
Code:
const express = require('express');
const jsonwebtoken = require('jsonwebtoken');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const {
postgraphql
} = require('postgraphql');
require('dotenv').config();
const app = express();
/**
* Routing
*/
app.all('/', (req, res) => {
res.status(200).json({
message: 'Hello world!!!'
});
});
/**
* PostgraphQL
*/
const pgConnection = {
host: 'localhost',
user: 'postgres',
password: 'postgres',
database: 'test_db',
port: 5432
};
const postgraphqlConfig = {
pgDefaultRole: 'anonymous',
graphiql: true,
};
app.use(postgraphql(pgConnection, 'public', postgraphqlConfig));
/**
* App starts
*/
app.listen(process.env.PORT, err => {
if (err) console.log(err);
else console.log(`Running at http://localhost:${process.env.PORT}`);
})
Error:
Error: You must provide a valid PG client configuration
at withPgClient (d:\learn\postgraphql_test\node_modules\graphile-build-pg\node8plus\withPgClient.js:47:13)
at introspect (d:\learn\postgraphql_test\node_modules\graphile-build-pg\node8plus\plugins\PgIntrospectionPlugin.js:48:39)
at PgIntrospectionPlugin (d:\learn\postgraphql_test\node_modules\graphile-build-pg\node8plus\plugins\PgIntrospectionPlugin.js:118:42)
at exports.getBuilder (d:\learn\postgraphql_test\node_modules\graphile-build\node8plus\index.js:20:11)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
at Function.Module.runMain (module.js:607:11)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
Possible cause:
The error only happens when I install/add pg NPM package.
Oops, good catch - that's a regression.
Nope, I mis-diagnosed. The issue here is that your version of pg and the version used internally by graphile-build-pg are not the same module, so our instanceof checks fail:
We set it as a peer dependency here:
The actual dependency is here:
So it looks like postgraphql is installing one version of pg, but graphile-build-pg is referencing the wrong version - I expect npm/yarn will have output a bad peer dependency warning?
To resolve, change your pg version to 6.x. I'll look into [email protected] support.
Works using [email protected]
having the same issue with :
not sure how to resolve that
using postgraphql@next instead of postgraphile solves the issue !
should we play with postgraphile or postgraphql ?
Please use postgraphql@next for now. postgraphile tends to lag because I don't spend the time to keep publishing - I only originally published it to reserve the package on npm so no :trollface: would steal it!
(EDIT: Use whichever you prefer.)
In fact...
/me adds a deprecation message.
ok thanks !
What actually needs to be done to add support for pg 7?
Don't know; it could just be updating the versions across all the package.jsons. I've not looked into it or any breaking changes yet. Have a read of the v7 changelog and let us know! 👍
I would like to know if there is a workaround to upgrade to 7, right now I suspect that some issues related to pool hang is because the older version which i'm using 6.x, and would like to upgrade but postgraphql doesn't work with 7.x
[email protected] support
Most helpful comment
Fixed in https://github.com/postgraphql/postgraphql/releases/tag/v4.0.0-alpha2.31