dotansimha / dotansimha/graphql-code-generator
Unable to disable type checking on schema import
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
### Describe the bug
# tl;dr
See minimal reproduction: https://github.com/edorivai/graphql-codegen-transpile-only
```bash
# this fails to load the schema due to a TS error in schema.ts
yarn generate
# now try with v1 of the cli - this seems to work
yarn add "@graphql-codegen@1"
yarn generate
```
# Details
When importing the schema from a TS code file, it is not possible to ignore TS errors.
Previously (with `@graphql-codegen@1`) we could specify a `transpile-only` ts-node loader:
```yaml
require:
- ts-node/register/transpile-only
```
This would load the schema as long as it was able to construct the schema at runtime, ignoring TS errors.
With version 2 of the codegen CLI, it seems that regardless of setting the `ts-node/register/transpile-only` _require_ option, it will fail when there are errors in the schema.
This is a very practical problem, because I am loading our schema by requiring our `graphql-modules` graph, which naturally hooks into our app code. As I'm developing, our app code could contain (intermediate) TS bugs, but it would still be able to generate the schema for codegen to run.
Now that I `transpile-only` is "ignored", I am forced to fix all TS errors before being able to generate.
One particularly gnarly problem that this causes is when rebasing:
1. Create a commit with new fields on the schema and corresponding resolver implementations
2. Perform git rebase
3. Conflict in generated types - too tedious to fix by hand, so I would just accept "theirs" and regenerate types
4. Because I picked "theirs" in the previous step, the resolver types are not available any more, this results in TS errors on my resolver implementation.
5. Due to these TS errors, I now cannot regenerate the types
## Ideal fix
Ideally I would be able to use `@swc-node/register` - since I want to bypass Typechecking, and `swc` is faster anyway. If that is difficult, `ts-node/register/transpile-only` would be a good second solution.
### Your Example Website or App
https://github.com/edorivai/graphql-codegen-transpile-only
### Steps to Reproduce the Bug or Issue
1. this fails to load the schema due to a TS error in schema.ts
```
yarn generate
```
2. now try with v1 of the cli - this seems to work
```
yarn add "@graphql-codegen@1"
yarn generate
```
### Expected behavior
I expect `graphql-codegen` to respect the use of `ts-node/register/transpile-only` in `config.require`. Instead, it seems that internally, TS schema files are loaded through `ts-node` _with typechecking enabled_.
### Screenshots or Videos
_No response_
### Platform
- OS: Ubuntu 20.04
- NodeJS: 16.3.2
- `graphql` version: 16.5.0
- `@graphql-codegen/*` version(s):
```
├─ @graphql-codegen/add@3.2.1
├─ @graphql-codegen/cli@2.11.6
├─ @graphql-codegen/core@2.6.2
├─ @graphql-codegen/plugin-helpers@2.6.2
├─ @graphql-codegen/schema-ast@2.5.1
├─ @graphql-codegen/typescript-operations@2.5.0
│ └─ @graphql-codegen/typescript@2.7.3
│ └─ @graphql-codegen/visitor-plugin-common@2.12.1
├─ @graphql-codegen/typescript@2.7.0
└─ @graphql-codegen/visitor-plugin-common@2.11.0
```
### Codegen Config File
```yaml
schema: schema.ts
documents: document.graphql
require:
- "ts-node/register/transpile-only"
generates:
types.ts:
plugins:
- typescript
- typescript-operations
```
### Additional context
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.