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.72k stars 1.31k forks source link

`documentMode: ‘string’` produces types incompatible with strict typescript #10021

Open vruffer opened 1 week ago

vruffer commented 1 week ago

Which packages are impacted by your issue?

@graphql-codegen/cli

Describe the bug

I want to prefice this by saying it might be a feature request, depending on how you look at it.

When using @graphql-codegen/cli with preset: ‘client’ and documentMode: ‘string’, the generated class TypedDocumentString is incompatible with the typescript options noImplicitOverride and exactOptionalPropertyChecks.

There is a workaround which is to disable those two rules, but since you cannot (as far as I can tell) create typescript rules specific to certain files, you have to disable the rules for the entire project.

Your Example Website or App

https://github.com/vruffer/graphql-strict-ts-error

Steps to Reproduce the Bug or Issue

  1. Clone repo
  2. Run yarn install
  3. Run yarn codegen
  4. Run yarn check

Expected behavior

I expected the generated typescript to be valid with the strictest settings possible

Screenshots or Videos

No response

Platform

Codegen Config File

{
  overwrite: true,
  generates: {
    './src/gql/': {
      schema: ['./src/schema.graphql'],
      preset: 'client',
      config: {
        documentMode: 'string',
      },
      documents: ['./src/operations.ts'],
    },
  },
}

Additional context

No response