graphile/pg-aggregates

Getting - Error: Option 'appendPlugins' should be an array of functions, found 'object' at index 0

fahricap opened this issue · 3 comments

Getting when using "PgAggregatesPlugin" plugin.

Error: Option 'appendPlugins' should be an array of functions, found 'object' at index 0
    at ensureValidPlugins (/data/intrepid/postpraphile-int/node_modules/postgraphile-core/node8plus/index.js:18:19)
    at getPostGraphileBuilder (/data/intrepid/postpraphile-int/node_modules/postgraphile-core/node8plus/index.js:169:5)
    at Object.watchPostGraphileSchema (/data/intrepid/postpraphile-int/node_modules/postgraphile-core/node8plus/index.js:245:62)
    at createGqlSchema (/data/intrepid/postpraphile-int/node_modules/postgraphile/build/postgraphile/postgraphile.js:108:65)
    at getPostgraphileSchemaBuilder (/data/intrepid/postpraphile-int/node_modules/postgraphile/build/postgraphile/postgraphile.js:58:30)
    at postgraphile (/data/intrepid/postpraphile-int/node_modules/postgraphile/build/postgraphile/postgraphile.js:261:53)
    at file:///data/intrepid/postpraphile-int/src/index.js:10:5
    at ModuleJob.run (node:internal/modules/esm/module_job:154:23)
    at async Loader.import (node:internal/modules/esm/loader:166:24)
    at async Object.loadESM (node:internal/process/esm_loader:68:5)

The issue does not happen when using another plugin.
It might also be related to the one mentioned here [https://github.com/graphile-contrib/pg-many-to-many/issues/64] mentioned for "pg-many-to-many" plugin.

The code for which I'm getting the exception.

import express from "express";
import { postgraphile } from 'postgraphile'
import ConnectionFilterPlugin from "postgraphile-plugin-connection-filter";
import PgAggregatesPlugin from "@graphile/pg-aggregates";
import PgManyToManyPlugin from '@graphile-contrib/pg-many-to-many'

const app = express();

app.use(
    postgraphile(
        process.env.DATABASE_URL || "postgres://XXX:YYYY*ZZZZZ@localhost:5432/TTTTT",
        "public",
        {
            watchPg: true,
            graphiql: true,
            enhanceGraphiql: true,
            extendedErrors: ['hint', 'detail', 'errcode'],
            appendPlugins: [PgAggregatesPlugin ]

        }
    )
);

app.listen(process.env.PORT || 5000);

And library versions:

  "dependencies": {
    "@graphile-contrib/pg-many-to-many": "^1.0.1",
    "@graphile-contrib/pg-simplify-inflector": "^6.1.0",
    "@graphile/pg-aggregates": "^0.1.0",
    "@types/node": "^15.12.5",
    "express": "^4.17.1",
    "postgraphile": "^4.12.5",
    "postgraphile-plugin-connection-filter": "^2.2.2",
    "prettier": "^2.3.2",
    "typescript": "^4.3.5"
  }

Try changing

import PgAggregatesPlugin from "@graphile/pg-aggregates";

to

import * as PgAggregatesPlugin from "@graphile/pg-aggregates";

Seems like an ESM/TypeScript/Babel/something misconfiguration issue.

Not sure this plugin is being bundled for ESM correctly. Putting this in the plugins list fixed it for me:

import PgAggregatesPlugin from '@graphile/pg-aggregates'
...
(PgAggregatesPlugin as any).default
benjie commented

This is fixed in V5.