dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.81k stars 1.32k forks source link

[cli] CLI stops handling local plugins written in TypeScript since v3.2.2 #9979

Open eddeee888 opened 4 months ago

eddeee888 commented 4 months ago

Which packages are impacted by your issue?

@graphql-codegen/cli

Describe the bug

Versions before v3.2.2 takes plugins written in TypeScript. However, we bumped a few dependencies in v3.2.2 that may have broken this feature.

Although, the examples in the doc are in .js and there's no mention of .ts support so I'm not sure if it was intentional

Steps to Reproduce the Bug or Issue

  1. Install v3.2.1: yarn add -DE @graphql-codegen/cli@3.2.1
  2. Add the following files
    
    // codegen.ts
    import type { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = { schema: "**/schema.graphql", generates: { "src/test.generated.ts": { plugins: ["src/plugin.ts"], }, }, }; export default config;

// src/plugin.ts export const plugin = () => { return "Hi from plugin!"; };

3. Running `graphql-codegen` creates `src/test.generated.ts` with `Hi from plugin!` as the content.
4. Change to v3.2.2: `yarn add -DE @graphql-codegen/cli@3.2.2`
5. Running `graphql-codegen` will show errors like this:

Unable to load template plugin matching 'src/plugin.ts'. Reason: Unexpected token 'export'



### Expected behavior

v3.2.2 and after should still take local TypeScript plugins.

### Screenshots or Videos

_No response_

### Platform

- OS: macOS
- NodeJS: 20
- `graphql` version: 16.8.0
- `@graphql-codegen/cli` version(s): 3.2.2

### Codegen Config File

_No response_

### Additional context

_No response_