Flowtype generation for queries with Inline Fragments
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
This is a proposed improvement to flowtype generation for the relay compiler.
When writing queries against a union type, we use Inline Fragments to select fields from one member of the union type. In the generated flowtypes, I am seeing a single object type with optional fields.
Flow does support union types as well, however. If we are able to map GraphQL union types to Flow union types, client code we can get improved static guarantees and reduce the amount of pessimistic runtime checks that we need to execute.
e.g.
With a schema that looks like this:
```graphql
type Query {
users: [User]!
}
type User = StudentUser | TeacherUser
type StudentUser {
name: String!
classes: [String]!
age: Int!
}
type TeacherUser {
name: String!
position: String!
title: String!
}
```
If my query looks like this:
```graphql
query AppQuery {
users {
... on StudentUser {
classes
age
}
... on TeacherUser {
position
title
}
}
}
```
I expect the generated flowtypes to look like this:
```javascript
type AppQueryResponse = {|
users: $ReadOnlyArray;
age: number;
|} | {|
position: string;
title: string;
|}>;
|}
```
But instead, I see this:
```javascript
type AppQueryResponse = {|
users: $ReadOnlyArray;
age?: number;
position?: string;
title?: string;
|}>;
|}
```
Contributor guide
Assessment
This issue has not been assessed yet.