apollographql / apollographql/apollo-tooling
client:codegen uses Flow "maybe" type for nullable fields, which allows undefined
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 460
- PR merge metrics
- No merged PRs in 30d
Description
Generated types for nullable (or non-required) fields use the Flow "maybe" type. This forces the client to do unnecessary type refinements.
For example, the following GraphQL type:
```
type Foo {
bar: String
baz: String!
}
```
...generates the following Flow type:
```
{
__typename: "Foo",
bar: ?string,
baz: string,
};
```
This is wrong because "maybe" types are allowed to be `undefined` in addition to `null` and the indicated type:
https://flow.org/en/docs/types/maybe/
I think the correct Flow type should be this:
```
{
__typename: "Foo",
bar: string | null,
baz: string,
};
```
**Versions**
apollo@^2.18.3
apollo-codegen-flow@^0.33.28
Contributor guide
Research direction
Start in the apollo-codegen-flow generator entry point that emits nullable field types and locate its existing Flow code-generation tests. Reproduce the Foo example, then verify that nullable or non-required fields produce a type allowing null but not undefined, while required fields remain unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100