dotansimha / dotansimha/graphql-code-generator

client-preset throws "invalid ast node" during react hot reload

Open
#9,553 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Is your feature request related to a problem? Please describe.

When modifying queries in development, codegen does not complete before react's hot reload re-runs code. As a result, the documents map is out of sync with the source code and we fall into the `{}` case in the generated `graphql` function

```
export function graphql(source: string) {
return (documents as any)[source] ?? {};
}
```

Since `{}` is not a valid AST node, the graphql client throws and error and development is halted.

### Describe the solution you'd like

For development, it would be ideal for the error not to be thrown when modifying queries. One solution would be for the fallback to be `gql(source)` instead of `{}`. The issue with that is we'd have to figure out how to eliminate the `gql` dependency in production.

### Describe alternatives you've considered

I haven't been able to come up with alternative solutions

### Is your feature request related to a problem? Please describe.

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.