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

importDocumentNodeExternallyFrom doesn't work

Open itpropro opened this issue 1 year ago • 0 comments

Which packages are impacted by your issue?

visitor-plugin-common

Describe the bug

The setting importDocumentNodeExternallyFrom implemented here https://github.com/dotansimha/graphql-code-generator/blob/d3dc84d821a43c61ea741e98d089d3753e398c15/packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts#L666 doesn't work as documented. As documented in on documentMode

external: document nodes are imported from an external file. To be used with importDocumentNodeExternallyFrom

and on `` itself

any string: This would be the path to import document nodes from. This can be used if we want to manually create the document nodes e.g. Use graphql-tag in a separate file and export the generated document

The only thing that it currently does is adding an import line to the generated file like this

import * as Operations from 'ANY_STRING';

This does not help for using external document nodes. It would be expected that either every type and operation in the file is prefixed with Operations. or that the proper imports from the given path are added (preferred). Now it just generates a file that is missing all type and operation references.

Steps to Reproduce the Bug or Issue

  1. Set documentMode to external
  2. Set importDocumentNodeExternallyFrom to the path of the generated types and operations
  3. Look if the generated file has all references correct

Expected behavior

Add correct import statements for each used type and operation from the provided path. Alternatively provide an option to prefix every operation with the imported object prefix, in this case Operations.. Currently there is only typesPrefix for types, nothing for operations.

Screenshots or Videos

No response

Platform

  • OS: macOS, Windows, Linux
  • NodeJS: 20
  • graphql version: 16.9
  • @graphql-codegen/* version(s): current

Codegen Config File

No response

Additional context

No response

itpropro avatar Sep 25 '24 21:09 itpropro