Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect imports when using union fragment with dedupeOperationSuffix: true and inlineFragmentTypes: 'combine' #812

Open
YoonjiJang opened this issue Aug 6, 2024 · 0 comments

Comments

@YoonjiJang
Copy link

Which packages are impacted by your issue?

@graphql-codegen/near-operation-file-preset

Describe the bug

Using dedupeOperationSuffix: true, inlineFragmentTypes: 'combine', and using union type together causes incorrect import names.

You'd expect that given the following fragment,

fragment UINodeFragment on UINode {
  ... on TextUINode {
    id
    content
  }
  ... on ImageUINode {
    id
    url
  }
}

which generates

export type UiNodeFragment_ImageUiNode = { __typename?: 'ImageUINode', id: string, url?: string | null };

export type UiNodeFragment_TextUiNode = { __typename?: 'TextUINode', id: string, content?: string | null };

export type UiNodeFragment = UiNodeFragment_ImageUiNode | UiNodeFragment_TextUiNode;

importing and using UINodeFragment in another operation will generate code that imports UiNodeFragment_ImageUiNode or UiNodeFragment_TextUiNode or UiNodeFragment.

Instead, generated code imports UiNodeFragment_ImageUiNode_ and UiNodeFragment_TextUiNode_, with additional undercores at the end.

Your Example Website or App

https://github.com/YoonjiJang/graphql-codegen-union-fragment

Steps to Reproduce the Bug or Issue

  1. Check out main branch from reproduction repository
  2. Run npm install
  3. Run npm run graphql-codegen

Expected behavior

The imports should be UiNodeFragment_ImageUiNode and UiNodeFragment_TextUiNode.

Screenshots or Videos

Screenshot 2024-08-06 at 10 39 47 PM

Platform

  • OS: macOS
  • NodeJS: v20.16.0
  • graphql version: 16.9.0
  • @graphql-codegen/cli: 5.0.2
  • @graphql-codegen/near-operation-file-preset: 3.0.0
  • @graphql-codegen/typescript: 4.0.9
  • @graphql-codegen/typescript-operations: 4.2.3

Codegen Config File

import { CodegenConfig } from "@graphql-codegen/cli";
import path from "path";

const config = {
  schema: [path.resolve(__dirname, "schema.graphql")],
  overwrite: true,
  generates: {
    "src/graphql/types.ts": {
      plugins: ["typescript"],
    },
    src: {
      preset: "near-operation-file",
      presetConfig: {
        extension: ".ts",
        baseTypesPath: "./graphql/types.ts",
      },
      plugins: ["typescript-operations"],
      config: {
        dedupeOperationSuffix: true,
        inlineFragmentTypes: "combine",
      },
      documents: [path.resolve(__dirname, "src/**/*.graphql")],
    },
  },
} satisfies CodegenConfig;

export default config;

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant