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

[Bug?]: Cannot generate enum types with GraphQL Codegen #6025

Open
1 task
tyteen4a03 opened this issue Jul 23, 2022 · 3 comments
Open
1 task

[Bug?]: Cannot generate enum types with GraphQL Codegen #6025

tyteen4a03 opened this issue Jul 23, 2022 · 3 comments
Assignees
Labels
bug/confirmed We have confirmed this is a bug

Comments

@tyteen4a03
Copy link

tyteen4a03 commented Jul 23, 2022

What's not working?

A prisma schema:

enum NameStatus {
    NAME_REQUESTED
    NAME_APPROVED
    NAME_DENIED
    NAME_CHANGING
}

ends up being this in GQL Schema:

  enum NameStatus {
    NAME_REQUESTED
    NAME_APPROVED
    NAME_DENIED
    NAME_CHANGING
  }

All fine thus far. But when you generate the TypeScript type it becomes:

export type NameStatus =
  | 'NAME_APPROVED'
  | 'NAME_CHANGING'
  | 'NAME_DENIED'
  | 'NAME_REQUESTED';

I put in this into codegen.yml at the root:

config:
  enumsAsTypes: true
  noExport: true

(noExport just to test if it's the file that's not getting passed down); only the noExport one got passed down and affected the GraphQL typedefs output. The enumAsTypes option got ignored and I'm stuck with no enums.

How do we reproduce the bug?

No response

What's your environment? (If it applies)

System:
    OS: macOS 12.4
    Shell: 5.9 - /opt/homebrew/bin/zsh
  Binaries:
    Node: 16.14.2 - /private/var/folders/cg/srfblk2d7bq2dw2tqjt94qkh0000gn/T/xfs-2b3a723a/node
    Yarn: 3.2.1 - /private/var/folders/cg/srfblk2d7bq2dw2tqjt94qkh0000gn/T/xfs-2b3a723a/yarn
  Databases:
    SQLite: 3.37.0 - /usr/bin/sqlite3
  Browsers:
    Chrome: 103.0.5060.134
    Firefox: 102.0.1
    Safari: 15.5
  npmPackages:
    @redwoodjs/core: 2.1.0 => 2.1.0

Are you interested in working on this?

  • I'm interested in working on this
@tyteen4a03 tyteen4a03 added the bug/needs-info More information is needed for reproduction label Jul 23, 2022
@redwoodjs-bot redwoodjs-bot bot added this to Main Jul 23, 2022
@redwoodjs-bot redwoodjs-bot bot moved this to Triage in Main Jul 23, 2022
@jtoar jtoar added bug/confirmed We have confirmed this is a bug action/add-to-cycle and removed bug/needs-info More information is needed for reproduction labels Aug 5, 2022
@redwoodjs-bot redwoodjs-bot bot moved this from Triage to In progress in Main Aug 5, 2022
@jtoar jtoar moved this from In progress to Todo in Main Aug 5, 2022
@jtoar
Copy link
Contributor

jtoar commented Aug 5, 2022

hey @tyteen4a03, we just discussed this one and will move on it soon—thanks for reporting!

@muhajirdev
Copy link

enumAsTypes seems to be hardcoded here

{ typescript: { enumsAsTypes: true } },

@dthyresson dthyresson moved this from Todo to In progress in Main Aug 23, 2022
@dthyresson
Copy link
Contributor

Note that the expected result for codegen for the enum when enumsAsTypes is false is:

export enum NameStatus {
  NAME_APPROVED = 'NAME_APPROVED',
  NAME_CHANGING = 'NAME_CHANGING',
  NAME_DENIED = 'NAME_DENIED',
  NAME_REQUESTED = 'NAME_REQUESTED'
}

when true:

export type NameStatus =
  | 'NAME_APPROVED'
  | 'NAME_CHANGING'
  | 'NAME_DENIED'
  | 'NAME_REQUESTED';

Which I can generate by changing

function getCodegenOptions(
  documents: CodegenTypes.DocumentFile[],
  config: CodegenTypes.PluginConfig,
  extraPlugins: CombinedPluginConfig[]
) {
  const plugins = [
    { typescript: { enumsAsTypes: true } }, // <----- here set to false
    ...extraPlugins.map((plugin) => ({ [plugin.name]: plugin.options })),
  ]

So, while I can set the config for settings like:

config:
  namingConvention:
    enumValues: change-case-all#upperCase
    typeNames: change-case-all#lowerCase

which change the case, the enumsAsTypes override doesn't appear to take effect.

@redwoodjs-bot redwoodjs-bot bot removed this from Main Aug 24, 2022
@redwoodjs-bot redwoodjs-bot bot added this to Main Nov 14, 2022
@redwoodjs-bot redwoodjs-bot bot removed this from Main Nov 14, 2022
@redwoodjs-bot redwoodjs-bot bot added this to Main Nov 14, 2022
@redwoodjs-bot redwoodjs-bot bot removed this from Main Nov 14, 2022
@redwoodjs-bot redwoodjs-bot bot added this to Main Dec 7, 2022
@redwoodjs-bot redwoodjs-bot bot removed this from Main Dec 7, 2022
@redwoodjs-bot redwoodjs-bot bot added this to Main Dec 7, 2022
@redwoodjs-bot redwoodjs-bot bot removed this from Main Dec 7, 2022
@redwoodjs-bot redwoodjs-bot bot added this to Main Dec 7, 2022
@redwoodjs-bot redwoodjs-bot bot removed this from Main Dec 7, 2022
@redwoodjs-bot redwoodjs-bot bot added this to Main Dec 7, 2022
@redwoodjs-bot redwoodjs-bot bot removed this from Main Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/confirmed We have confirmed this is a bug
Projects
None yet
4 participants