dotansimha / graphql-code-generator

A tool for generating code based on a GraphQL schema and GraphQL operations (query/mutation/subscription), with flexible support for custom plugins.
https://the-guild.dev/graphql/codegen/
MIT License
10.81k stars 1.32k forks source link

Supporting gql tag functions #10020

Open steelbrain opened 3 months ago

steelbrain commented 3 months ago

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

Currently graphql-tag-operations only emits typings when graphql function is used as a normal function. Any kind of mixing or interpolation throws it off. The way it's setup we cannot use GraphQL fragments and get the automagical typing

Describe the solution you'd like

Since we have access to the sources, I suggest we create additional typings (could be hidden behind a flag) that when enabled, will emit Template Literals tag-function friendly types.

These could look like

export function gql(strings: ['\n query Query {\n', 'name }'], ...args: unknown)

The reference isn't perfect but you get the idea

Describe alternatives you've considered

No response

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

Yes. If you have a use case where you make use of fragments, you have to do a lot of hard-coding that could be automated with this feature