eddeee888 / graphql-code-generator-plugins

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

[FEAT] Enum Resolvers #265

Closed Teddy-Wilson closed 3 months ago

Teddy-Wilson commented 5 months ago

Is your feature request related to a problem? Please describe. Unless I've missed it theres currently no way to generate resolvers for GraphQL enum types.

Describe the solution you'd like

  1. add enums to the resolverGeneration object
  2. generate enum resolvers files.

Describe alternatives you've considered None. But open to other alternatives if they exist.

Additional context N/A

eddeee888 commented 5 months ago

Hi @Teddy-Wilson,

Thank you for the request 🙌 It's definitely something I will be looking to add this soon.

In the meantime, you can add external (or missing/custom) resolvers using externalResolvers config.

For example, if you have the following schema:

# src/schema/country/schema.graphql
enum Country {
  US
  UK
  AU
}

Then, you can manually create the enum resolver:

// src/schema/country/resolvers/Country.ts
import type { CountryResolvers } from '../../types.generated';

export const Country: CountryResolvers = {
  US: 'US',
  UK: 'UK',
  AU: 'AU'
};

And wire it up to resolvers.generated.ts using this config:

// codegen.ts
defineConfig({
  externalResolvers: {
    Country: 'src/schema/country/resolvers/Country.ts'
  }
})
eddeee888 commented 3 months ago

Hi @Teddy-Wilson ,

This feature is implemented in this PR, released as alpha version pr293-run533-1

Could you please install it and try it out please? 🙏

yarn add -DE @eddeee888/gcg-typescript-resolver-files@pr293-run533-1
eddeee888 commented 3 months ago

This is now implemented in v0.10