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.87k stars 1.34k forks source link

Extract generated client queries #10195

Open jh-grundfos opened 1 week ago

jh-grundfos commented 1 week ago

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

Hey

I'm in need of a CLI or similar to extract all queries from a client app. The intended use is for mocking, testing and perhaps query whitelisting in production.

The Apollo CLI had this feature

https://github.com/apollographql/apollo-tooling/?tab=readme-ov-file#apollo-clientextract-output

However, that repo is actively being deprecated and is no longer maintainted, and not compatible with newer versions of Node.

I thought this might be something on your radar/roadmap as maintainers of

@graphql-codegen/cli and @graphql-codegen/client-preset ?

A button to export queries active on an environment on the Hive dashboard could also make sense, but maybe that request should be specifically made to the Hive team?

Describe the solution you'd like

A tool that extracts the queries in an app that uses @graphql-codegen/cli, preferably to a JSON output.

Describe alternatives you've considered

https://github.com/apollographql/apollo-tooling/?tab=readme-ov-file#apollo-clientextract-output

Any additional important details?

No response

eddeee888 commented 5 days ago

Hi @jh-grundfos ,

Interesting! Could you please help me understand the behaviour by giving a small example of what the outcome would look like?

For example, if I have these two queries, what would be the outcome?

# src/User.graphql
query User {
  user(id: "1") {
    id
    name
  }
}

# src/Book.graphql
query Book {
  book(id: "1") {
    id
    isbn
  }
}