graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

typed-document-node doesn't import fragments with documentMode: "documentNodeImportFragments"

Open alexeyr-ci opened this issue 1 year ago • 0 comments

Which packages are impacted by your issue?

@graphql-codegen/typed-document-node

Describe the bug

When I use typed-document-node plugin and documentMode is documentNodeImportFragments, the generated document node doesn't import fragments.

Your Example Website or App

https://github.com/alexeyr-ci/typed-document-node-import-fragments/tree/main

https://codesandbox.io/p/github/alexeyr-ci/typed-document-node-import-fragments/main

Steps to Reproduce the Bug or Issue

  1. Rerun generate task.
  2. Open types.ts.

Expected behavior

I expected the definition of UserDocument to include ...UserFragmentFragmentDoc.definitions, but it doesn't.

For comparison, if you uncomment typescript-react-apollo in codegen config (and optionally comment out typed-document-node), you can see it does include UserFragmentFragmentDoc.

In our real use-case, the fragment is in a separate file, but the result is the same.

Screenshots or Videos

No response

Platform

  • OS: Linux
  • NodeJS: v16.17.0
  • graphql version: 16.8.1
  • "@graphql-codegen/add": "^5.0.0", "@graphql-codegen/cli": "^4.0.1", "@graphql-codegen/typed-document-node": "^5.0.1", "@graphql-codegen/typescript": "^4.0.1", "@graphql-codegen/typescript-operations": "^4.0.1", "@graphql-codegen/typescript-react-apollo": "^4.1.0", "graphql": "^16.2.0"

Codegen Config File

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

const config: CodegenConfig = { schema: "schema.graphql", documents: "document.graphql", generates: { "types.ts": { plugins: [ "typescript", "typescript-operations", "typed-document-node", // "typescript-react-apollo", ], config: { documentMode: "documentNodeImportFragments", }, }, }, };

export default config;

Additional context

I was hoping to use this document mode to reduce bundle size. However, I made a hacky way to check the result, and it seems to not work well in our use-case, so this isn't high priority for me.

alexeyr-ci avatar Dec 03 '23 13:12 alexeyr-ci