Referencing named queries using string literals can be cumbersome/bug-prone. Having an auto-generated enum containing all named queries would help with that.
Apollo example, but might be applicable more widely:
mutation MyMutation {
# ...
}
query MyQuery {
# ...
}
```ts
myMutationGQL
.mutate(
{ id, patch },
{ refetchQueries: ['MyQuery'] } // <---- 'MyQuery' literal
);
An auto-generated enum would ease this a little:
```ts
// graphql.ts
export enum NamedQueries {
MyQuery = 'MyQuery'
}
// usage
import { NamedQueries } from './graphql.ts'
myMutationGQL
.mutate(
{ id, patch },
{ refetchQueries: [NamedQueries.MyQuery] } // <---- No more typos + auto-completion
);
Implemented this in: https://github.com/dotansimha/graphql-code-generator/pull/4039
Available in v1.14.0.
Thanks! :)
Most helpful comment
Implemented this in: https://github.com/dotansimha/graphql-code-generator/pull/4039