Postgraphile: Adding custom plugging

58 views Asked by At

I have a database in PostgreSQL (db name: contacts, schema: contacts, table: contacts). I am trying to add a pluggin to postgraphile using makeExtendSchemaPlugin. My code :

import { makeExtendSchemaPlugin, gql } from "graphile-utils";
import  DataUtil  from "@syncfusion/ej2-data";

const MyPlugin = makeExtendSchemaPlugin(build => {
  // Get any helpers we need from `build`
//   const { pgSql: sql, inflection } = build;

  return {
    typeDefs: gql`
        input DataManager {
            skip: Int
            take: Int
            group: [String]
            table: String
            select: [String]
            where: String
            search: String
            requiresCounts: Boolean,
            params: String
            }
        
        type ReturnType {
            result: [contacts]
            count: Int
            }

        extend type Query {
            getOrders(datamanager: DataManager): ReturnType
            }

    `,
    resolvers: {
        Query: {
            getOrders: (_, args) => {
             var ret = DataUtil.DataUtil.processData(args.datamanager, contacts);
    
             return ret;
            }
           }
    },
  };
});

module.exports = MyPlugin;

and my package.json :

{
    "name": "@graphile-examples/schema_only",
    "version": "1.0.0",
    "private": true,
    "type": "module",
    "dependencies": {
        "@graphile-contrib/pg-simplify-inflector": "^6.1.0",
        "@syncfusion/ej2-data": "^23.1.36",
        "graphql": "^16.8.1",
        "pg": "^8.11.3",
        "postgraphile": "^4.13.0"
    }
}

and then when I try to run the command :

postgraphile -c postgres://postgres:postgres+@localhost/contacts -s contacts -a -j --append-plugins C:/Users/DragonSlayer/Desktop/postrgraphile-exemple/MySchemaExtensionPlugin.js

I get the error : Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\DragonSlayer\Desktop\postrgraphile-exemple\MySchemaExtensionPlugin.js from C:\Users\DragonSlayer\AppData\Roaming\npm\node_modules\postgraphile\build\postgraphile\cli.js not supported. at Array.map () at loadPlugins (C:\Users\DragonSlayer\AppData\Roaming\npm\node_modules\postgraphile\build\postgraphile\cli.js:281:18) at Object. (C:\Users\DragonSlayer\AppData\Roaming\npm\node_modules\postgraphile\build\postgraphile\cli.js:358:23) at Object. (C:\Users\DragonSlayer\AppData\Roaming\npm\node_modules\postgraphile\cli.js:5:20) { code: 'ERR_REQUIRE_ESM' }

How can I fixe the error ?

NOTE: my Node.js version is 18.18.0

0

There are 0 answers