eddeee888 / graphql-code-generator-plugins

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

Disable generation of resolvers for types? #226

Closed alecrobertson1 closed 2 months ago

alecrobertson1 commented 5 months ago

When I run codegen, I get resolvers generated for all my types even if I don't use them. I don't require them to be implemented as I return all the information in the top-level query resolver, so is there a way to disable the generation of these resolvers?

eddeee888 commented 4 months ago

Hello @alecrobertson1 πŸ‘‹

Not now, but this can be implemented fairly easily πŸ™‚

The config would look something like this:

'src/schemas': defineConfig({
  resolverGeneration: {
    query: true,
    mutation: true,
    subscription: true,
    scalar: true,
    object: false, // This disables object type generation.
    union: false,
    interface: false,
  }
}),

I will add comments here when it's ready. Thanks for raising the question!

eddeee888 commented 3 months ago

Hi @alecrobertson1, could you please try out this alpha version?

yarn add -D @eddeee888/gcg-typescript-resolver-files@pr240-run411-1

And the new definteConfig for your use case may look like this:

defineConfig({
  resolverGeneration: {
    query: '*',
    mutation: '*',
    subscription: '*',
    scalar: '*',
    object: '', // Empty string disables all resolver generation in every module.
    union: '',
    interface: '',
  },
})

Here's the WIP PR: https://github.com/eddeee888/graphql-code-generator-plugins/pull/240 I'll follow up with more documentation, examples and use cases soon

hcentelles commented 2 months ago

Hi @alecrobertson1, could you please try out this alpha version?

yarn add -D @eddeee888/gcg-typescript-resolver-files@pr240-run411-1

And the new definteConfig for your use case may look like this:

defineConfig({
  resolverGeneration: {
    query: '*',
    mutation: '*',
    subscription: '*',
    scalar: '*',
    object: '', // Empty string disables all resolver generation in every module.
    union: '',
    interface: '',
  },
})

Here's the WIP PR: #240 I'll follow up with more documentation, examples and use cases soon

Hi @eddeee888 is this available in v0.7.5?

It shows me this error when trying:

ERROR: Validation - presetConfig.resolverGeneration must be "disabled", "recommended" or "all" (default is "re…

EDIT: I looked into the package history and saw it's not there yet.

eddeee888 commented 2 months ago

Hi @hcentelles πŸ‘‹

This will be in v0.8 soon: https://github.com/eddeee888/graphql-code-generator-plugins/pull/250

I'm just doing some final cleanups before releasing this version this week.

eddeee888 commented 2 months ago

Hi @hcentelles ,

This is now available in v0.8. Please let me know if it doesn't solve your issue! Thank you!

hcentelles commented 2 months ago

Hi @hcentelles ,

This is now available in v0.8. Please let me know if it doesn't solve your issue! Thank you!

It works, thanks.

alecrobertson1 commented 1 month ago

Apologies for the late reply, this is brilliant. Thanks!

eddeee888 commented 1 month ago

This mode of resolverGeneration is regularly requested, so it can be set using resolverGeneration: 'minimal' from v0.9