dotansimha / dotansimha/graphql-code-generator
Avoid InputMaybe for some properties
- 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.
We are using Typescript and typescript, typescript-operations and typed-document-node plugins. We have adopted a standard for updating persistent entities via GraphQL using the following rules:
If the input attribute value is undefined leave the persistent entity attribute as is.
If the input attribute value is null, clear the persistent entity attribute.
if the input attribute values is not null or undefined, update the persistent entity attribute with the input attribute value.
Some persistent entity values are required. As an example, lets say use have a User where name is always required but phoneNumber is not. I want to be able to generate an input structure as:
```typescript
type UpdateUserInput = {
name?: Scalars['String']['input'];
phoneNumber?: InputMaybe;
}
```
This indicates I can update user.name with a value. I can also have name set to undefined and my back end can then preserve user.name during the update. It also indicates that I cannot set user.name to null because a user is required to have a name and we are using null to clear those things that are not required.
I feel that these update rules are fairly standard and have used them on quite a number of projects.
### Describe the solution you'd like
Not sure. A way to configure individual GraphQL properties to include or exclude InputMaybe. This seems like a good use of GraphQL annotations, but I know very little about these.
### Describe alternatives you've considered
Currently, for those attributes that are required but can be ignored in an update, I just allow null but convert it to undefined in my mutation code. This leads to code that is not as readable / self documenting as I would like.
### 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.