dotansimha / dotansimha/graphql-code-generator
Mention tsconfig-paths for codegen.ts?
- 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?
_No response_
### Describe the bug
If you are using a `paths` section in your `tsconfig.json`, the `codegen.ts` config will fail to load if it exports any code from your project. This can happen, for instance, if you are using Pathos, which recommends providing the scheme as a string to the config.
```bash
❯ npm run gql-codegen
> gql-codegen
> graphql-codegen
TypeScriptLoader failed to compile TypeScript:
Cannot find module '@lib/model-settings'
Require stack:
- /Users/artyom/code/windorg/woc/lib/graphql/schema/user.ts
- /Users/artyom/code/windorg/woc/lib/graphql/schema.ts
- /Users/artyom/code/windorg/woc/codegen.ts
- /Users/artyom/code/windorg/woc/node_modules/cosmiconfig-typescript-loader/dist/cjs/index.js
- ...
```
The solution is to add this section to your `tsconfig.json`:
```json
"ts-node": {
"require": [
"tsconfig-paths/register"
]
}
```
And install `npm i -D tsconfig-paths`.
I suppose this could be mentioned in the getting-started guide, but I don't know where in particular.
### Your Example Website or App
-
### Steps to Reproduce the Bug or Issue
-
### Expected behavior
-
### Screenshots or Videos
-
### Platform
- OS: macOS
- NodeJS: 16.18.0
- `graphql` version: 16.6.0
- `@graphql-codegen/cli@2.16.2`
- `@graphql-codegen/client-preset@1.2.6`
### Codegen Config File
```ts
import type { CodegenConfig } from '@graphql-codegen/cli'
import { printSchema } from 'graphql'
import { schema } from '@lib/graphql/schema'
const config: CodegenConfig = {
schema: printSchema(schema),
documents: ['{components,lib,pages}/**/!(*.graphql).{ts,tsx}'],
generates: {
'./generated/graphql/': {
preset: 'client',
plugins: [],
},
},
}
export default config
```
### Additional context
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.