dotansimha/graphql-code-generator-community

[Flow] wrong type of nullable operation using inline fragments (union)

Open

#122 aperta il 7 apr 2021

Vedi su GitHub
 (0 commenti) (1 reazione) (0 assegnatari)TypeScript (195 fork)github user discovery
help wanted

Metriche repository

Star
 (136 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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.

  1. 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!
}
  1. My GraphQL operations:
  fragment SubEntityFragment on Entity {
    ... on SubEntityA {
      subEntityFieldA
    }
    ... on SubEntityB {
      subEntityFieldB
    }
  }

  query getEntity {
    data: getEntity {
      ...SubEntityFragment
      field
    }
  }
  1. My codegen.yml config 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

Guida contributor