RFC: Run prettier over generated files if a config exists
mxstbr opened this issue · comments
Summary
Every time I run dev
my VSCode sidebar looks like this, even if I haven't changed anything about my schema:
![CleanShot 2023-12-15 at 10 07 26@2x](https://private-user-images.githubusercontent.com/7525670/290777621-2ff00915-f81e-4e71-a543-9bdfad33ba91.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjI5NDc2ODUsIm5iZiI6MTcyMjk0NzM4NSwicGF0aCI6Ii83NTI1NjcwLzI5MDc3NzYyMS0yZmYwMDkxNS1mODFlLTRlNzEtYTU0My05YmRmYWQzM2JhOTEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgwNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MDZUMTIyOTQ1WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NWE4NmM0NWMwNDczYTk3ZGRmYmJiZjZjZGYxNDQ0OGMzYzRjMWFjYTQxOTk5MTc1Y2U5NTNlODZiZmU3ZjQ3OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.C2RR9Y4INz_PSjU_DuvQ5PtoktbwTnSrOd5IKLvlyHM)
This happens because I use prettier, which formats files differently than the codegen.
Proposed Solution
If there is a prettier config file in the folder or a parent folder, run prettier over the generated code with the actual config to avoid unnecessary git diffs.
This should be implemented in GraphQL Code Generator, we basically have to detect whether the user has either got prettier installed (no config) or has a prettier config and then add the following to the GraphQL Code Generator process.
hooks: { afterAllFileWrite: ['prettier --write'] }
On it :)