Introduce `omitFields` option for typescript plugin

Author: yukukotaniCreated May 22, 2023Updated Sep 20, 2026

Is your feature request related to a problem? Please describe.

Let's think about the schema below:

graphql
type User {
  id: ID!
  name: String!
  tasks: [Task!]!
}
type Task {
  id: ID!
  name: String!
}
type Query {
  user(id: ID!): User
}

The User type in the generated code would be like this:

typescript
export type User = {
  __typename?: 'User';
  name: Scalars['String'];
  tasks: Array<Task>;
};

On server-side, this is comfortable on naive usecase. But when we resolve tasks field by field resolver, the return type of user query should not contains tasks.

We can partially address this issue using mappers option of typescript-resolver plugin. But it just replace the return type of resolvers so that base type still contains every fields.

I'd like to use the types generated by codegen outside resolvers such as repository-layer. And it should not contians the fields that resolved by field resolvers.

Describe the solution you'd like

Add omitFields option to typescript plugin. It will be configured like below:

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

const config: CodegenConfig = {
  generates: {
    './gen/graphql.ts': {
      config: {
        omitFields: {
          User: ['tasks'],
        }
      },
      plugins: [
        'typescript',
        'typescript-resolvers',
      ],
    },
  },
};
export default config;

Then it will generates User type like below:

typescript
export type User = {
  __typename?: 'User';
  name: Scalars['String'];
};

Describe alternatives you've considered

No response

Is your feature request related to a problem? Please describe.

No response

Source: dotansimha/graphql-code-generator