dotansimha / dotansimha/graphql-code-generator
Introduce `omitFields` option for typescript plugin
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
### 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:
```ts
export type User = {
__typename?: 'User';
name: Scalars['String'];
tasks: Array;
};
```
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:
```ts
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:
```ts
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_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.