Im using the following graphql-codegen config to generate typescript graphql code.
- First output includes all type definitions and resolver types (typescript - typescript-resolvers)
- Second output includes apollo hooks and operation types/codes which of base type definition depends on first output using
baseTypesPath
(typescript-operations- typescript-react-apollo)
Using enumValues
for resolvers correctly generated and mapped but generated operation & apollo hooks use the internal values for query arguments because it reference the base type enum values
Problem is that generated operation code use internal enum instead of sdl enum so it fails when making query that enum value is incorrect
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