dotansimha / dotansimha/graphql-code-generator-community

[typescript-react-query] `_externalImportPrefix` is not applied when using the `import-types` preset

Open
#493 2 comments 1 reaction 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/typescript-react-query

### Describe the bug

Since updating to `typescript-react-query@6.0.0` the prefix is missing for all types generated by this plugin. The problem are these lines: https://github.com/dotansimha/graphql-code-generator-community/blob/935b51f0777047102cc1c33a1a18a4527902e0f9/packages/plugins/typescript/react-query/src/visitor.ts#L148-L149

These variables are not used after this modification, only the `generateConfig` variable defined prior to these lines ( are passed to the functions on the next lines.

https://github.com/dotansimha/graphql-code-generator-community/blob/935b51f0777047102cc1c33a1a18a4527902e0f9/packages/plugins/typescript/react-query/src/visitor.ts#L139-L146

I fixed it by setting it while defining this variable:
```ts
const generateConfig = {
node,
documentVariableName,
operationResultType: this._externalImportPrefix + operationResultType,
operationVariablesTypes: this._externalImportPrefix + operationVariablesTypes,
hasRequiredVariables,
operationName,
};
```

### Your Example Website or App

-

### Steps to Reproduce the Bug or Issue

Run a codegen with the `typescript-react-query` plugin and the preset `import-types`. Config:

```ts
'./libs/shared/api/src/lib/src/generated.client.ts': {
documents: [
'./libs/shared/api/src/lib/graphql/client/**/*.graphql',
'./libs/shared/api/src/lib/graphql/shared/**/*.graphql',
],
plugins: ['typescript-react-query'],
preset: 'import-types',
presetConfig: {
typesPath: './generated.types',
},
config: {
namingConvention: {
enumValues: 'keep',
},
importOperationTypesFrom: 'Types',
reactQueryVersion: 5,
fetcher: './fetcher#fetcher',
exposeQueryKeys: true,
exposeMutationKeys: true,
},
},
```

### Expected behavior

It is possible to use the `import-types` preset.

### Screenshots or Videos

_No response_

### Platform

- OS: [e.g. macOS]
- NodeJS: [e.g. 20.8.0]
- `"graphql": "^16.8.1"`
- `"@graphql-codegen/typescript-react-query": "6.0.0"`
- `"@graphql-codegen/import-types-preset": "^3.0.0"`

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