【问题标题】:How do I make Graphql Code Generator for typescript make its enums into pascal case instead of snake case?如何为 typescript 制作 Graphql 代码生成器,使其枚举成为帕斯卡大小写而不是蛇形大小写?
【发布时间】:2021-11-22 18:17:15
【问题描述】:

目前,Graphql 代码生成器生成的枚举如下所示

export enum Test_Type {
    Test: 'TEST',
}

但是我希望生成的枚举是这样的帕斯卡大小写:

export enum TestType {
  Test: 'TEST',
}

编辑,我的 codegen.yml:

overwrite: true
generates:
  src/graphql/generated/graphql.ts:
    schema: ${API_ENDPOINT}
    documents: ['src/graphql/**/*.graphql', 'src/graphql/**/*.gql']
    plugins:
      - 'typescript'
      - 'typescript-operations'
      - 'typescript-react-apollo'
  ./graphql.schema.json:
    schema: ${API_ENDPOINT}
    plugins:
      - 'introspection'
hooks:
  afterAllFileWrite:
    - prettier --write

枚举的架构是

enum TEST_TYPE {
    TEST
}

【问题讨论】:

  • graphql-code-generator.com/docs/getting-started/…?请添加包含枚举的 graphql 架构以及您的 codegen.yaml 配置,否则我们无法为您提供帮助。
  • @Bergi 我将帖子编辑到我的 codegen.yml 。我认为我不能提供 graphql 模式,因为它是私有的。在这种情况下是否有必要,因为我问的是一个与实际模式无关的一般性问题?
  • 谢谢。不是整个架构,只有 enum TestType = TEST
  • @Bergi 我已经包含了该枚举的架构。提前感谢您的帮助。

标签: javascript typescript graphql graphql-codegen pascalcasing


【解决方案1】:

您可以在codegen.yml 文件的配置中设置naming convention

config:
  namingConvention: change-case-all#pascalCase

【讨论】:

    猜你喜欢
    • 2020-12-22
    • 2015-10-10
    • 2021-01-03
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-08
    相关资源
    最近更新 更多