dotansimha/graphql-code-generator-community

Missing HOC suffix dedup leads to invalid generated types with `dedupeOperationSuffix` and `withHOC` options.

Open

#138 ouverte le 13 juil. 2021

Voir sur GitHub
 (1 commentaire) (1 réaction) (0 assignés)TypeScript (195 forks)github user discovery
help wanted

Métriques du dépôt

Stars
 (136 stars)
Métriques de merge PR
 (Métriques PR en attente)

Description

Describe the bug

The HOC generics are missing a name deduplication... https://github.com/dotansimha/graphql-code-generator/blob/0538923f0cee884f95136b3ac794f83238cee568/packages/plugins/typescript/react-apollo/src/visitor.ts#L181

So it generates:

export type GetUserInformationQueryVariables = Types.Exact<{ [key: string]: never; }>;

export type GetUserInformationQuery = (
// ...
);

// ...
export type GetUserInformationQueryProps<TChildProps = {}, TDataName extends string = 'data'> = {
      [key in TDataName]: ApolloReactHoc.DataValue<GetUserInformationQueryQuery, GetUserInformationQueryQueryVariables>
    } & TChildProps;

GetUserInformationQueryQuery, GetUserInformationQueryQueryVariables should be GetUserInformationQuery, GetUserInformationQueryVariables

To Reproduce

If a live reproduction is necessary I can create one.

  1. My GraphQL schema:
# Put your schema here
  1. My GraphQL operations:
# Put your operations here
  1. My codegen.yml config file:
# ...
        preset: near-operation-file
        presetConfig:
            extension: .generated.tsx
            baseTypesPath: webapp_gql.ts
        plugins:
            - typescript-operations
            - typescript-react-apollo
        config:
            reactApolloVersion: 2
            withHooks: true
            withHOC: true
            withComponent: true
            gqlImport: graphql.macro#gql
            dedupeFragments: true
            dedupeOperationSuffix: true
            exportFragmentSpreadSubTypes: true

Expected behavior

GetUserInformationQueryQuery, GetUserInformationQueryQueryVariables should be GetUserInformationQuery, GetUserInformationQueryVariables

Generics should dedup when HOC is enabled.

Environment:

  • OS: macOS
  • @graphql-codegen/...: latest
  • NodeJS: v14

Additional context

Happy to add more context, but I believe I found the broken line.

Guide contributeur