0

我使用以下 graphql-codegen 配置来生成打字稿 graphql 代码。

  • 第一个输出包括所有类型定义和解析器类型(typescript - typescript-resolvers)
  • 第二个输出包括 apollo 钩子和操作类型/代码,其基本类型定义取决于使用baseTypesPath(typescript-operations- typescript-react-apollo) 的第一个输出

使用enumValues正确生成和映射的解析器,但生成的操作和阿波罗挂钩使用查询参数的内部值,因为它引用基本类型枚举值

问题是生成的操作代码使用内部枚举而不是 sdl 枚举,因此在查询枚举值不正确时会失败

schema:
  - ./api/graphql/schema/types.ts
  - ./api/graphql/schema/**/!(index.ts)*.ts    
generates:
  # For backend
  ./api/graphql/__generated__.ts:       
    plugins:
      - typescript
      - typescript-resolvers
    config:
      enumValues: ../db/enums
  # For client
  ./client/views:
    documents:
      - './client/views/**/*.gql'
      - './client/components/**/*.gql'
    preset: near-operation-file
    presetConfig:
      extension: .generated.tsx
      baseTypesPath: ../../api/graphql/__generated__.ts
      folder: __generated__
    config:         
      withHooks: true         
      reactApolloVersion: 3
    plugins:
      - typescript-operations
      - typescript-react-apollo
 
4

0 回答 0