tjmoses / postgraphile-plugin-batch-create-update-delete

A postgraphile plugin that allows for batch create, update, & delete mutations in a single transaction.
https://www.npmjs.com/package/postgraphile-plugin-many-create-update-delete
MIT License
37 stars 9 forks source link

esm import fails #14

Open rfdrake27 opened 2 years ago

rfdrake27 commented 2 years ago

Targeting esnext, importing

import ManyUpdatePlugin from 'postgraphile-plugin-many-create-update-delete';

and then using it in the appendPlugin array, appendPlugins: [ ManyUpdatePlugin, ]

will fail with the error that the appendPlugins param accepts functions, but the plugin is attempting to pass an object. However, the Typescript type is a Plugin.

If you ignore typescript warnings and import the plugin's default key, it will build appropriately:

appendPlugins: [ // @ts-ignore ManyUpdatePlugin.default, ]

tjmoses commented 2 years ago

1.) Can you provide your typescript version and tsconfig file? 2.) What version of node are you using? 3.) Do you have any other build steps involved?

innermatrix commented 1 year ago

I ran into this same issue @tjmoses

The problem and the solution are summarized at

https://arethetypeswrong.github.io/?p=postgraphile-plugin-many-create-update-delete%401.0.7

Repro steps are

  1. Create an ESM module
  2. Import the package
  3. Run tsc to see the error

Here's my code that shows same issue; you can paste this into a blank ESM module to repro

import  ManyUpdatePlugin from 'postgraphile-plugin-many-create-update-delete';
import { createPostGraphileSchema } from 'postgraphile';

async function generateGraphQLSchema() {
    await createPostGraphileSchema('', 'app_public_v2', {
        appendPlugins: [ManyUpdatePlugin],
    });
}

and the error is

test.ts:6:19 - error TS2322: Type 'typeof import("/Users/iris/Software/folx/test/b/node_modules/postgraphile-plugin-many-create-update-delete/build/index")' is not assignable to type 'Plugin'.
  Type 'typeof import("/Users/iris/Software/folx/test/b/node_modules/postgraphile-plugin-many-create-update-delete/build/index")' provides no match for the signature '(builder: SchemaBuilder, options: Options): void | Promise<void>'.

6   appendPlugins: [ManyUpdatePlugin],
                    ~~~~~~~~~~~~~~~~

Found 1 error in test.ts:6

The issue can be fixed either by adding an export = or by switching this module to ESM