dotansimha / dotansimha/graphql-code-generator-community

Cannot import typescript operation definition file with 'near-operation-plugin' and document: external

Open
#672 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

### Which packages are impacted by your issue?

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

### Describe the bug

Hello!

When using 'near-operation-file' with 'typescript-react-apollo' (but I guess it's the same with other plugins), we cannot import typescript files containing queries/mutations, only .graphql files work

### Your Example Website or App

https://codesandbox.io/p/devbox/youthful-bose-wxjhxz

### Steps to Reproduce the Bug or Issue

Using this config:
```
import { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
schema: "schema.graphql",
documents: "document.ts",
emitLegacyCommonJSImports: false,
generates: {
".": {
plugins: ["typescript-react-apollo"],
preset: "near-operation-file",
presetConfig: {
baseTypesPath: "./types.ts",
},
config: {
importDocumentNodeExternallyFrom: "near-operation-file",
importOperationTypesFrom: "Types",
documentMode: "external",
},
},
"types.ts": { plugins: ["typescript", "typescript-operations"] },
},
};

export default config;
```

this config makes sense: the goal is to import queries/mutations defined in typescript files into local mtFile.generated.ts

### Expected behavior

in the reproduction repository, line 25 of document.generated.ts should be:
`return Apollo.useQuery(Operations.userQuery, options); ``

and not:
`return Apollo.useQuery(Operations.user, options);`

userQuery is the name of the typescript variable, whereas user is the name of the graphql query

### Screenshots or Videos

_No response_

### Platform

- OS: MacOS
- NodeJS: 18
- `graphql` 16.3.0
- `@graphql-codegen/*` version(s): latest

### Codegen Config File

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

const config: CodegenConfig = {
schema: "schema.graphql",
documents: "document.ts",
emitLegacyCommonJSImports: false,
generates: {
".": {
plugins: ["typescript-react-apollo"],
preset: "near-operation-file",
presetConfig: {
baseTypesPath: "./types.ts",
},
config: {
importDocumentNodeExternallyFrom: "near-operation-file",
importOperationTypesFrom: "Types",
documentMode: "external",
},
},
"types.ts": { plugins: ["typescript", "typescript-operations"] },
},
};

export default config;
```

### Additional context

remotely related to https://github.com/dotansimha/graphql-code-generator/issues/3272#issuecomment-1427850754

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.