dotansimha / dotansimha/graphql-code-generator-community
[near-operation-file] "'Types' is defined but never used." in generated files
- 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
`near-operation-file`-generated files always import `Types` from the main type file as follows:
```js
import * as Types from './types';
```
However, if `Types` is unused (which appears to be pretty common in our codebase), this will result in errors if your lint setup enforces "no unused vars" rules such as [`no-unused-vars `](https://eslint.org/docs/latest/rules/no-unused-vars)or [`@typescript-eslint/no-unused-vars`](https://typescript-eslint.io/rules/no-unused-vars).
### Your Example Website or App
https://codesandbox.io/p/sandbox/festive-framework-bjr117?file=%2Fdocument.generated.d.ts&selection=%5B%7B%22endColumn%22%3A3%2C%22endLineNumber%22%3A1%2C%22startColumn%22%3A3%2C%22startLineNumber%22%3A1%7D%5D
### Steps to Reproduce the Bug or Issue
See attached codesandbox.io example.
Specifically, notice the `import` statement at the top of "document.generated.d.ts".
### Expected behavior
`Types` import statements should only be included in the generated output if `Types` is actually used in the file.
### Screenshots or Videos

### Platform
```
$ npx envinfo --system --browsers --npmPackages --binaries
System:
OS: macOS 13.0
CPU: (10) x64 Apple M1 Max
Memory: 19.34 MB / 64.00 GB
Shell: 5.1.8 - /usr/local/bin/bash
Binaries:
Node: 16.18.0 - ~/.nvm/versions/node/v16.18.0/bin/node
Yarn: 1.18.0 - ~/.nvm/versions/node/v16.18.0/bin/yarn
npm: 9.5.0 - ~/.nvm/versions/node/v16.18.0/bin/npm
Watchman: 2023.01.30.00 - /usr/local/bin/watchman
Browsers:
Chrome: 110.0.5481.100
Firefox: 108.0.2
Safari: 16.1
npmPackages:
@babel/core: 7 => 7.20.12
@babel/eslint-parser: ^7.15.8 => 7.19.1
@babel/preset-react: ^7.14.5 => 7.18.6
@evilmartians/lefthook: ^1.2.9 => 1.2.9
@trivago/prettier-plugin-sort-imports: ^4 => 4.0.0
@typescript-eslint/eslint-plugin: ^5.38.1 => 5.49.0
@typescript-eslint/parser: ^5.38.1 => 5.49.0
@vue/compiler-sfc: 3.2.21 => 3.2.21
cypress: ^10.3.0 => 10.11.0
eslint: ^8.0.0 => 8.33.0
eslint-plugin-graphql: ^4.0.0 => 4.0.0
eslint-plugin-import: ^2.25.2 => 2.27.5
eslint-plugin-jest: ^26.1.5 => 26.9.0
eslint-plugin-jsx-a11y: ^6.6.1 => 6.7.1
eslint-plugin-node: ^11.1.0 => 11.1.0
eslint-plugin-promise: ^4.3.1 => 4.3.1
eslint-plugin-react: ^7.22.0 => 7.32.2
eslint-plugin-react-hooks: ^4.0.8 => 4.6.0
eslint-plugin-sonarjs: ^0.16.0 => 0.16.0
eslint-plugin-unicorn: ^44.0.2 => 44.0.2
glob: ^8.0.3 => 8.1.0
graphql: 15.5.1 => 15.5.1
jest: ^29.4.1 => 29.4.1
postcss: 8.4.16 => 8.4.16
postcss-scss: 4.0.5 => 4.0.5
prettier: ^2.8.3 => 2.8.3
react: ^17.0.2 => 17.0.2
react-dom: 17.0.2 => 17.0.2
stylelint: ^14.12.0 => 14.16.1
stylelint-config-standard: ^28.0.0 => 28.0.0
stylelint-scss: ^4.3.0 => 4.3.0
ts-jest: ^29.0.3 => 29.0.5
tsc-watch: ^6.0.0 => 6.0.0
typescript: ^4.9.4 => 4.9.5
```
### Codegen Config File
See attachee example
### Additional context
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.