dotansimha / dotansimha/graphql-code-generator
Custom TS schema loaders are not working
- 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?
@graphql-codegen/cli
### Describe the bug
I am following the [guide](https://the-guild.dev/graphql/codegen/docs/config-reference/schema-field#loading-api-url-from-typescript-file-example) for creating a custom loader using TS.
It appears that the codegen fails to load the `.ts` loader file yet works ok with a `.js` one.
### Your Example Website or App
https://codesandbox.io/p/sandbox/graphql-codegen-custom-schema-loader-issue-hkve7f
### Steps to Reproduce the Bug or Issue
- Run `yarn generate`
The command fails with an error
- Change `loader.ts` to `loader.js` in `codegen.ts`
- Run `yarn generate`
This time the command will work
### Expected behavior
As a user, I expected that the custom schema loader written in TS will work if I follow the [guide](https://the-guild.dev/graphql/codegen/docs/config-reference/schema-field#loading-api-url-from-typescript-file-example)
### Screenshots or Videos
_No response_
### Platform
- OS: [e.g. macOS, Linux]
- NodeJS: 16.17.0
- `graphql` version: 16.2.0
- `@graphql-codegen/*` version(s): 2.6.2
### Codegen Config File
```TS
import { CodegenConfig } from "@graphql-codegen/cli";
const config: CodegenConfig = {
schema: {
"schema.graphql": {
// loader: "./loader.js", // JS - ✅ working
loader: "./loader.ts", // TS - ❌ not working
},
},
documents: "document.graphql",
generates: {
"types.ts": { plugins: ["typescript", "typescript-operations"] },
},
};
export default config;
```
### Additional context
Please, note that I am registering the `ts-node` for the codegen command.
```
graphql-codegen -r ts-node/register --config ./codegen.ts
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.