kamilkisiela / graphql-config

One configuration for all your GraphQL tools (supported by most tools, editors & IDEs)
https://the-guild.dev/graphql/config
MIT License
1.16k stars 93 forks source link

Support code files (js, ts) as schema files #1425

Open addiebarron opened 2 months ago

addiebarron commented 2 months ago

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

I work on a project that defines its GraphQL schema in gql tags across a number of .ts files in the server directory. We generate a schema.graphql file from those code files in the pre-commit step using graphql-codegen, but during development the most up-to-date information about the schema is in those gql tags, not in the schema.graphql file.

Furthermore, in my IDE, clicking through any client-side definitions (e.g. a query name in a query operation) sends me to the generated schema rather than the typescript source, which is what we'd consider the "source of truth". (I recognize this could also be implemented as an IDE feature. I'll make a ticket there as well).

Describe the solution you'd like

Graphql config files should support js/ts files in the schema field. Consumers can parse the graphql from those files as they choose.

Describe alternatives you've considered

The only working alternative now is to search the codebase for the definitions as they appear in Typescript.

Additional context

Some kind of "source map" concept could potentially solve this as well. I wish I could integrate directly with graphql-codegen!

addiebarron commented 2 months ago

I noticed this is technically possible, as certain tools do integrate with documents this way (vscode's graphql lsp-server supports this albeit in a limited/buggy capacity). It would be great to have the behavior formalized and added to the docs! I'd be willing to make that docs PR but I don't know enough about the library's behavior to describe it accurately.