dotansimha / dotansimha/graphql-code-generator-community
`near-operation-file` does not import scalars, leading to broken code
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
### Which packages are impacted by your issue?
`near-operation-file` preset
### Describe the bug
When a .gql document contains a query to a field that is a custom scalar, the generated .ts file does not import the scalar, and therefore TypeScript build fails.
### Your Example Website or App
https://github.com/rixth/gql-repro
### Steps to Reproduce the Bug or Issue
1. Run `npm i && npx graphql-code-generator -v --config codegen.ts`
2. Open `src/Query.gql.generated.ts`
3. Observe that `MyScalar` is underlined red, as it is not resolved or imported, despite `scalars: { MyScalar: './ExternalType#MyScalar' }` being passed in `codegen.ts`
### Expected behavior
`import { MyScalar } from './ExternalType';` should have been added to the top of the file (such as it is in the base `types.generated.ts` file)
### Screenshots or Videos
_No response_
### Platform
- OS: macOS
- NodeJS: 14.21.3
- `graphql` version: 16.6.0
- `@graphql-codegen/cli`: 3.3.1
- `@graphql-codegen/near-operation-file-preset`: 2.5.0
- `@graphql-codegen/typescript`: 3.0.4
- `@graphql-codegen/typescript-operations`: 3.0.
### Codegen Config File
```ts
import { CodegenConfig } from '@graphql-codegen/cli';
const scalars = {
MyScalar: './ExternalType#MyScalar',
};
const config: CodegenConfig = {
schema: [
'src/GqlTypedef.ts',
],
documents: ['src/Query.gql'],
generates: {
'./src/types.generated.ts': {
config: {
skipTypename: true,
avoidOptionals: true,
strictScalars: true,
scalars,
},
plugins: ['typescript'],
},
'./': {
preset: 'near-operation-file',
presetConfig: {
extension: '.gql.generated.ts',
baseTypesPath: './src/types.generated.ts',
},
config: {
skipTypename: true,
avoidOptionals: true,
strictScalars: true,
scalars,
},
plugins: ['typescript-operations'],
},
},
};
export default config;
```
### Additional context
_updated patch and test in comments_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.