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.84k stars 1.33k forks source link

client-preset does not generate types for deprecated input fields when using introspection #9354

Open kdawgwilk opened 1 year ago

kdawgwilk commented 1 year ago

Which packages are impacted by your issue?

@graphql-codegen/client-preset

Describe the bug

The following type in SDL

input MyInput {
  foo: Boolean
  """
  Will be removed later
  """
  bar: Boolean @deprecated(reason: "Will be removed later")
}

Generates the following TS types using the client-preset

export type TemplatesFilter = {
  foo?: InputMaybe<Scalars['Boolean']>;
};

Your Example Website or App

https://codesandbox.io/p/sandbox/muddy-leaf-wuqws1?file=%2Frenovate.json&selection=%5B%7B%22endColumn%22%3A37%2C%22endLineNumber%22%3A12%2C%22startColumn%22%3A37%2C%22startLineNumber%22%3A12%7D%5D

Steps to Reproduce the Bug or Issue

  1. Open code sandbox (will run apollo server with schema)
  2. Start a new command yarn codegen:watch
  3. Inspect the types/graphql.ts UserFilter type
  4. deprecated field is not there

Expected behavior

The generated TS types should include deprecated fields

Screenshots or Videos

No response

Platform

Codegen Config File

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

const config: CodegenConfig = {
  overwrite: true,
  ignoreNoDocuments: true, // for better experience with the watcher
  generates: {
    'lib/gql/': {
      preset: 'client',
      schema: {
        'http://localhost:4040/graphql': {
          headers: {
            Authorization: 'Bearer XXXXXXXX',
          },
        },
      },
      documents: ['{pages,lib,components}/**/*.{ts,tsx,js,jsx}'],
    },
  },
  config: {
    namingConvention: 'keep',
    scalars: {
      DateTime: 'string',
      JSON: 'unknown',
      Upload: 'unknown',
      Time: 'string',
      Date: 'string',
      Long: 'number',
      Url: 'string',
    },
  },
}

export default config

Additional context

No response

leonchabbey commented 1 year ago

https://github.com/dotansimha/graphql-code-generator/pull/7769#issuecomment-1189228744 You can use inputValueDeprecation: true to override the default config. It brings back the input types, however the jsdoc comments are missing instead of adding them the same way as for a type's fields. I didn't find a solution to this.

kdawgwilk commented 1 year ago

Is there a way to just set inputValueDeprecation: true for only one of the schemas we are generating for rather than at the top level? One of our schemas introspection does not support deprecated input args so I need to disable it for that one specifically