Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[experimental-graphql-modules] no config in generation for enums #5242

Open
Tracked by #8296 ...
maapteh opened this issue Dec 11, 2020 · 4 comments
Open
Tracked by #8296 ...

[experimental-graphql-modules] no config in generation for enums #5242

maapteh opened this issue Dec 11, 2020 · 4 comments
Labels
core Related to codegen core/cli help wanted Extra attention is needed kind/enhancement New feature or request presets Related to Codegen presets

Comments

@maapteh
Copy link
Contributor

maapteh commented Dec 11, 2020

Im using the new experimental graphql-module creation. In the old schema creation we had this config:

        config:
            constEnums: true
            avoidOptionals: true
            namingConvention:
                enumValues: change-case#upperCase

Now the new graphql-modules option creates the complete schema but i cant set any config. So i lost all my enums basically (which follow TS spec, also saw it with DTS generator). I can create the other as well, but why having two schemas :)

example new situation:

/** Order your items */
export type BasketListOrdering = 
  /** By department, which is based on product taxonomy */
  | 'DEPARTMENT'
  /** By latest item added first */
  | 'INPUT';

example old situation:

/** Order your items */
export const enum BasketListOrdering {
    /** By department, which is based on product taxonomy */
    DEPARTMENT = 'DEPARTMENT',
    /** By latest item added first */
    INPUT = 'INPUT',
}

btw really cool to see the progress on the suite!

@dotansimha
Copy link
Owner

Hi!
Thank you for reporting it.
We do allow custom configurations, but not for enums customizations.

In this new preset, we generate main types file with everything in it, and then generate types file per graphql-module, with the contribution of it to the result schema.

Since TypeScript enums are nominal types, we can define the entire enum in the main file, and the pick specific values from it.
The only way to allow this kind of flow where main types files defined everything and each module types file takes what it needs is to use const string enums, instead of enum.

Do you think there is another way to solve that?

@dotansimha dotansimha added the waiting-for-answer Waiting for answer from author label Dec 14, 2020
@maapteh
Copy link
Contributor Author

maapteh commented Dec 14, 2020

No not really unfortunately. I hope to work on it next year since now i only have three working days left :)

@maapteh maapteh changed the title no config in experimental graphql-modules generation [experimental-graphql-modules] no config in generation for enums Dec 14, 2020
@dotansimha dotansimha added enhancement presets Related to Codegen presets and removed waiting-for-answer Waiting for answer from author labels Dec 15, 2020
@jjangga0214
Copy link

jjangga0214 commented Apr 7, 2021

@dotansimha
@maapteh

The only way to allow this kind of flow where main types files defined everything and each module types file takes what it needs is to use const string enums, instead of enum.

Do you think there is another way to solve that?

I don't understand why.. just importing typescript enum from main file to module file, like what config: enumsAsTypes would do, isn't enough to solve that?

P.S.
Currently, config: enumsAsTypes does not work with graphql-modules preset, and I feel this is inconsistent in a natural user's viewpoint.

@jjangga0214
Copy link

jjangga0214 commented Apr 7, 2021

Workaround for other folks until the issue is resolved.

You can generate typescript enum only with typescript (without graphql-modules).
Then, you can configure config: enumsValues (ref1, ref2) on graphql-modules generation.

overwrite: true
generates:
  ./src/generated/graphql/self-enum.ts:
    schema:
      - ./src/graphql/module/*/*.graphql:
          commentDescriptions: true
    plugins:
      - typescript
    config:
      typesPrefix: Gql
  ./src/graphql/module:
    schema:
      - ./src/graphql/module/*/*.graphql:
          commentDescriptions: true
    preset: graphql-modules
    presetConfig:
      baseTypesPath: ../../generated/graphql/self.ts # Where to create the complete schema types
      filename: generated.ts # Where to create each module types
    plugins:
      - typescript
      - typescript-resolvers
    config:
      typesPrefix: Gql
      # enumsAsTypes: false # This does not work with graphql-modules preset. 
      enumValues:
        foo: ./self-enum#GqlFoo
        bar: ./self-enum#GqlBar

And you can import enum types independently.

import { YourModule } from './generated'
import { GqlFooEnum, GqlBarEnum } from '../../../generated/garphql/self-enum'

// the enums are compatible with graphql-modules' generated enums.

@dotansimha dotansimha added help wanted Extra attention is needed kind/enhancement New feature or request and removed need-help labels Jun 20, 2021
@charlypoly charlypoly added the core Related to codegen core/cli label Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli help wanted Extra attention is needed kind/enhancement New feature or request presets Related to Codegen presets
Projects
None yet
Development

No branches or pull requests

4 participants