dotansimha/graphql-code-generator
View on GitHubMention tsconfig-paths for codegen.ts?
Open
#8838 opened on Jan 20, 2023
help wanted
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.
❯ 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:
"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
graphqlversion: 16.6.0@graphql-codegen/cli@2.16.2@graphql-codegen/client-preset@1.2.6
Codegen Config File
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