eddeee888 / graphql-code-generator-plugins

List of GraphQL Code Generator plugins that complements the official plugins.
MIT License
46 stars 11 forks source link

Question: Is there a way to reformat the output #191

Closed anli-xsigns closed 6 months ago

anli-xsigns commented 8 months ago

First of all - thanks for the amazing work! I love to use this plugin! Sorry for asking this question here - I didn't find another appropriate location: Is there a way to influence the output of the generated files? I want to

How the file is generated: Schnappschuss_102923_024325_PM

How it would be optimal in my case: Schnappschuss_102923_025142_PM

Thanks a lot for your help in advance!

eddeee888 commented 8 months ago

Hello @anli-xsigns ! Thanks for using the plugin!

I highly recommend using GraphQL Codegen's Lifecyle hooks to format the file using your formatter of choice e.g. Prettier.

Here's an example config:

const config: CodegenConfig = {
  hooks: { 
    afterAllFileWrite: ['prettier --write'] // `afterAllFileWrite` runs command after all files are written
  },
  schema: ['*.graphql'],
  generates: {
    // ... your usual config
  },
};

You can then running Codegen as usual and the commands given to the hook will run at appropriate time. 🙂

eddeee888 commented 6 months ago

Closing this issue because it looks like it solved the issue. Please open another issue if you see other problems. Thank you!