[Flow] wrong type of nullable operation using inline fragments (union)
#122 opened on Apr 7, 2021
Repository metrics
- Stars
- (136 stars)
- PR merge metrics
- (PR metrics pending)
Description
Describe the bug There is a query operation with nullable return type (graphql interface). It uses graphql inline fragments (union) based on two types implementing the interface. In result of graphql code generation to flow types first branch of the union is marked as maybe type, but second one is not. See below repository and instructions for more details.
To Reproduce Steps to reproduce the behavior: There is a repository prepared for reproduction. You can just review the code or re-run codegen script on your own.
- My GraphQL schema:
type Query {
getEntity: Entity # the key moment return type is nullable
}
interface Entity {
field: String!
}
type SubEntityA implements Entity {
field: String!
subEntityFieldA: String!
}
type SubEntityB implements Entity {
field: String!
subEntityFieldB: String!
}
- My GraphQL operations:
fragment SubEntityFragment on Entity {
... on SubEntityA {
subEntityFieldA
}
... on SubEntityB {
subEntityFieldB
}
}
query getEntity {
data: getEntity {
...SubEntityFragment
field
}
}
- My
codegen.ymlconfig file:
schema: ./schema.graphql
documents:
- ./query.js
generates:
./graphql.types.js:
plugins:
- flow
- flow-operations
config:
preResolveTypes: true
Expected behavior
It is expected that all branches of generated query type would be marked as maybe types.
Environment:
- OS: MacOS Big Sur version 11.12.3, Windows 10
@graphql-codegen/add: 2.0.2@graphql-codegen/cli: 1.21.3@graphql-codegen/flow: 1.18.5@graphql-codegen/flow-operations: 1.18.7- NodeJS: v12.13.0