dotansimha / dotansimha/graphql-code-generator

add an option to add a `class-transformer` `Type` decorator when using `Class` as `declarationKind`

Open
#9,664 0 comments 0 reactions 0 assignees View on GitHub
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.

I'm using `client-preset` generation, but also a second round in order to generate Classes for my inputs.

This allow me to use `new Class()` in my front in order to clean data before sending it to backend as input data.

I'm doing it manually but would like to switch to `plainToClass(User, fromPlainUser, { excludeExtraneousValues: true })` from `class-transformer`

I'm pretty new with it, so i've just discovered that you can use `@Type` descriptor to automatically map entities relationships.
It would be super useful to avoid having to manually check any nested entity content during data cleaning.

### Describe the solution you'd like

When generating classes, `graphql-codegen` outputs :

```
/** Material Input */
export class MaterialInput {
/** Material's id */
_id?: InputMaybe;
/** Material's coding config */
codingConfig: CodingConfigUnionInput;
/** Material's content */
content?: InputMaybe;
/** Material's cost usages */
costUsages: Array;
/** Material's label */
label: Scalars['String']['input'];
/** Material's status id */
statusId: Scalars['Id']['input'];
/** Material's title */
title?: InputMaybe;
};
```

It would be great to be able to generate :
```
/** Material Input */
export class MaterialInput {
// ...
/** Material's cost usages */
@Type(() => CostUsageInput)
costUsages: Array;
// ...
};
```

### 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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.