dotansimha / dotansimha/graphql-code-generator

[Java] Wrap Nullable Fields in Optional Class

Open
#1,906 0 comments 2 reactions 0 assignees View on GitHub
kind/enhancement plugins
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.**

If a field is nullable in the schema it's not reflected in the code generated by gql-gen.

```graphql
input NullableExample {
nullableField: String
notNullable: String!
}
```
```java
class MutationNameArgs {
private String _nullableField;
private String _notNullable;

public String getNullableField() { return this._nullableField; }
public String getNotNullable() { return this._notNullable; }
}
```

**Describe the solution you'd like**
It would be great if there was an option to have fields be `Optional`s if they are optional in the schema.

```java
class MutationNameArgs {
private String _nullableField;
private String _notNullable;

public Optional getNullableField() { return Optional.ofNullable(this._nullableField); }
public String getNotNullable() { return this._notNullable; }
}
```

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.