Postgraphile: [v4] Add support for [email protected]

Created on 14 Aug 2017  ·  13Comments  ·  Source: graphile/postgraphile

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.

👨‍💻 Fix in v4

Most helpful comment

All 13 comments

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:

https://github.com/graphile/graphile-build/blob/ca0eda0c10f64067119e0cb4e7d9a40815a28fb8/packages/graphile-build-pg/src/withPgClient.js#L17-L24

We set it as a peer dependency here:

https://github.com/graphile/graphile-build/blob/ca0eda0c10f64067119e0cb4e7d9a40815a28fb8/packages/graphile-build-pg/package.json#L50

The actual dependency is here:

https://github.com/postgraphql/postgraphql/blob/5979eafcb2fe4c675870b265aeca8ff68d7d053e/package.json#L47

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 :

  • "pg": "^6.4.2",
  • "postgraphile": "^4.0.0-alpha2.12"

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

angelosarto picture angelosarto  ·  3Comments

WestleyArgentum picture WestleyArgentum  ·  3Comments

CarlFMateus picture CarlFMateus  ·  4Comments

safaiyeh picture safaiyeh  ·  3Comments

jwdotjs picture jwdotjs  ·  5Comments