dotansimha/graphql-code-generator-community

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

Open

#138 创建于 2021年7月13日

在 GitHub 查看
 (1 评论) (1 反应) (0 负责人)TypeScript (195 fork)github user discovery
help wanted

仓库指标

Star
 (136 star)
PR 合并指标
 (PR 指标待抓取)

描述

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.

贡献者指南