eddeee888 / graphql-code-generator-plugins

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

[FEAT] Format generated files using projects prettier/eslint config #235

Closed kdawgwilk closed 4 months ago

kdawgwilk commented 4 months ago

Is your feature request related to a problem? Please describe. The code generated does not line up with my formatting settings and so every time I go to commit I have to run the formatter for all code generated

Describe the solution you'd like It would be great if the generated code was formatted to match my projects settings automatically during generation

Describe alternatives you've considered Hook into the code gen process and run the formatted myself as a post generation step, not sure if the right hooks are available for this

kdawgwilk commented 4 months ago

I was able to find the right hooks and add this in

config: CodegenConfig = {
  schema: 'api/**/schema.graphql',
  ignoreNoDocuments: true, // for better experience with the watcher
  generates: {
    'api/src/schema': {
      ...defineConfig({
        typesPluginsConfig: {
          contextType: './context.js#Context',
        },
        emitLegacyCommonJSImports: false,
      }),
      hooks: {
        afterOneFileWrite: ['prettier --write'],
      },
    },
    'web/src/lib/gql/': {
      preset: 'client',
      documents: 'web/src/**/*.tsx',
    },
  },
};