graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

`@graphql-codegen/add` only adds text to `graphql.ts`

Open nagisa-yamato opened this issue 1 year ago • 6 comments

Which packages are impacted by your issue?

@graphql-codegen/client-preset

Describe the bug

I want to add // @ts-nocheck to all files generated by client-preset. However, when I use @graphql-codegen/add, it only adds to graphql.ts.

Your Example Website or App

https://stackblitz.com/edit/stackblitz-starters-teuxdr?file=codegen.ts

Steps to Reproduce the Bug or Issue

  1. Open the example above
  2. npm run codegen
  3. Check the output in ./src/gql
  4. // @ts-nocheck is only added to graphql.ts

Expected behavior

// @ts-nocheck is added to all files generated by @graphql-codegen/client-preset.

Screenshots or Videos

No response

Platform

Codegen Config File

import type { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
  overwrite: true,
  schema: 'https://countries.trevorblades.com/graphql',
  documents: 'src/**/!(*.d).{ts,tsx}',
  generates: {
    'src/gql/': {
      preset: 'client',
      plugins: [
        {
          add: {
            content: '// @ts-nocheck',
          },
        },
      ],
    },
  },
};

export default config;

Additional context

No response

nagisa-yamato avatar Jul 28 '23 02:07 nagisa-yamato

I also come across this issue, does anyone know how to solve this?

carterax avatar Oct 26 '23 20:10 carterax

any news?

falkomerr avatar Jan 27 '24 15:01 falkomerr

Can confirm this is still a problem in "@graphql-codegen/add": "5.0.2".

mseeley avatar Feb 22 '24 06:02 mseeley

And still a problem in "@graphql-codegen/add": "5.0.3"!

aoumiri avatar Jul 24 '24 15:07 aoumiri

Can you share why you want to add @ts-nocheck to each file? The client preset should not be used in combination with other plugins, if there is a need to prepend to the emitted files, we can talk about adding this!

n1ru4l avatar Jul 28 '24 13:07 n1ru4l

@n1ru4l it's not only about @ts-nocheck. It's anything we want to add. Could be //tslint ignore.

I could add a hook, but as per the documentation:

Before adding a hook, consider the alternative of having codegen ignored in your linting. Codegen files should not be edited manually and formatting them slows down your codegen considerably. Differences can be measured in several seconds for every run on big projects.

The issue, is that it only adds it to the graphql.ts file, and not to the fragment-masking for example. And I don't want to tweak my ts/lint config to deal with autogenerated files.

Is there an alternative? If not I will go with a hook and a --fix, but without having the guarantee that all errors will be auto-fixable.

aoumiri avatar Jul 29 '24 10:07 aoumiri