dotansimha / dotansimha/graphql-code-generator

importDocumentNodeExternallyFrom doesn't work

Open
#10,153 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### 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_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.