altair-graphql / altair

✨⚡️ A feature-rich GraphQL Client for all platforms.
https://altairgraphql.dev
MIT License
5.13k stars 320 forks source link

[BUG] Altair Fastify plugin not compatible with nodenext #2666

Open kingston opened 1 month ago

kingston commented 1 month ago

Is there an existing issue for this?

Current Behavior

Using the Fastify plugin in an ESM Fastify app results in a Typescript build error.

src/plugins/graphql/index.ts:147:28 - error TS2769: No overload matches this call.
  Overload 1 of 3, '(plugin: FastifyPluginCallback<{ path: string; baseURL: string; endpointURL: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'typeof import("/.../node_modules/.pnpm/altair-fastify-plugin@7.2.4_fastify@4.28.1/node_modules/altair-fastify-plugin/dist/index")' is not assignable to parameter of type 'FastifyPluginCallback<{ path: string; baseURL: string; endpointURL: string; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.

Expected Behavior

The plugin should be able to be used with ESM enabled.

Steps To Reproduce

Set "type": "module" in your package.json and add typescript support.

import AltairFastify from 'altair-fastify-plugin';
import Fastify from 'fastify';

const app = Fastify();

app.register(AltairFastify);

Environment

- OS: Mac
- Browser: N/A
- Platform: Node.JS
- Version: 20

Additional context

Fastify has fixed their plugins using the "infamous triplet" with module.exports (https://github.com/fastify/fastify/issues/4349). Ideally it can be applied to this plugin so it supports both CJS/ESM seamlessly.

imolorhe commented 4 days ago

We can mark this as closed now?