Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Manipulate the generated file #425

Open
Hebilicious opened this issue Dec 1, 2024 · 0 comments
Open

RFC: Manipulate the generated file #425

Hebilicious opened this issue Dec 1, 2024 · 0 comments
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release

Comments

@Hebilicious
Copy link

Hebilicious commented Dec 1, 2024

Summary

It would be great if we could manipulate the generated file in some ways, such as appending/or preprending code, or executing code after the generation with some kind of hook.

Use case :

The introspected file has

/* eslint-disable */
/* prettier-ignore */

appended to it, but I'm currently using another linter (dprint) that needs dprint-ignore. Currently I'm patching the internal package to add stuff there, but that's not ideal.

Proposed Solution

I haven't thought too much about it, but there's 2 things that could work :

  1. Add a pre and post settings in the schemas property of the plugin, so we can pass abitrary code there.
    This would be good for a simple use case. For example a linter use case you'd do something like this :
    "plugins": [
      {
        "name": "gql.tada/ts-plugin",
        "schemas": [
          {
            "name": "my-api",
            "schema": "./src/graphql/my-api.graphql",
            "tadaOutputLocation": "./src/graphql/my-api_env.d.ts",
            "tadaTurboLocation": "./src/graphql/my-api_cache_env.d.ts",
			"pre": "// dprint-ignore-file \n"
          }
        ]
      }
  1. Add a beforeGeneration and afterGeneration hook, that will run a command with child_process.
    This would be very flexible, for the linter use case it would allow to run a linter after each generation.
    "plugins": [
      {
        "name": "gql.tada/ts-plugin",
        "schemas": [
          {
            "name": "my-api",
            "schema": "./src/graphql/my-api.graphql",
            "tadaOutputLocation": "./src/graphql/my-api_env.d.ts",
            "tadaTurboLocation": "./src/graphql/my-api_cache_env.d.ts",
			"afterGeneration": "bun run ./scripts/lint-gql-tada-output.ts"
          }
        ]
      }

Requirements

@Hebilicious Hebilicious added the future 🔮 An enhancement or feature proposal that will be addressed after the next release label Dec 1, 2024
@Hebilicious Hebilicious changed the title RFC: Manipulate the introspected file RFC: Manipulate the generated file Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release
Projects
None yet
Development

No branches or pull requests

1 participant