postgraphile-plugin-batch-create-update-delete icon indicating copy to clipboard operation
postgraphile-plugin-batch-create-update-delete copied to clipboard

esm import fails

Open rfdrake27 opened this issue 3 years ago • 2 comments

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, ]

rfdrake27 avatar Jun 17 '22 05:06 rfdrake27

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?

tjmoses avatar Jun 17 '22 17:06 tjmoses

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

innermatrix avatar Sep 20 '23 16:09 innermatrix