Skip to content

type generation breaks on @graphql-codegen/[email protected]  #5166

@lauromueller

Description

@lauromueller

Before describing the bug, let me just drop a big "thank you" for this code generator. Saves a lot of time and headache when managing our React + Apollo app 🙂

Describe the bug

We currently use @graphql-codegen/[email protected] to generate graphql types and helper hooks for the Apollo Client serving our application. So far everything is working fine, however, when trying to update to version 2.2.1, the generated types start to contain several [object Object] instances.

More precisely, this happens within generated Pick<...> types. For example, suppose I have the following type definition:

type MyType {
  myFirstField: String;
  mySecondField: String;
}

extend type Query {
  myObject: MyType
}

query getMyTypeFirstField {
  myObject {
    myFirstField
  }
}

Then the result of running the generator outputs a broken type definition:

export type MyTypeFields = Maybe<{ __typename: 'MyType' } & Pick<MyType, '[object Object]'>>

The expected output would be:

export type MyTypeFields = Maybe<{ __typename: 'MyType' } & Pick<MyType, 'myFirstField'>>

My guess is that this is related to #5104, as the definitions for MakeOptional were updated and MakeMaybe was introduced.

My codegen.yml config file:

overwrite: true
hooks:
  afterAllFileWrite:
    - "yarn prettier:fix"
schema:
  - "src/types/cache/cacheTypeDefs.ts"
documents:
  - "src/**/*.ts"
generates:
  src/types/generated/cacheTypes.tsx:
    plugins:
      - "typescript"
      - "typescript-operations"
      - "typescript-react-apollo"
  ./graphql.schema.json:
    plugins:
      - "introspection"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions