mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-21 08:15:23 -04:00
b691e05879
After the `chore(frontend): upgrade graphql-codegen toolchain` upgrade
(8a3d4e9) the generated `src/graphql/types.ts` carried every base type
twice — once as `export enum Foo` (from `typescript`) and once as
`export type Foo = 'a' | 'b'` (from `typescript-operations`). Vite's
dependency scan failed on the duplicate declarations with 29
`Identifier 'X' has already been declared` parse errors, which made
the dev server occasionally die on cold start.
Root cause: this was a stale v5-style config running on v6 plugins.
The v6 migration guide is explicit — `preResolveTypes` has been
removed, and `typescript-operations@6` now emits base types itself,
so the canonical setup is `plugins: ['typescript-operations']` rather
than `['typescript', 'typescript-operations']`. Keeping both meant the
two plugins independently emitted the full type set in different
shapes.
Bisect confirmed the split: `typescript` alone → 1327 lines, no
duplicates; `typescript-operations` alone → 1311 lines, no
duplicates; the pair → 2639 lines with 29 duplicate type names.
With `typescript-react-apollo` also in the mix the regenerated file
ballooned to 8819 lines, half of which was the shadow set.
Fix:
- Drop the `typescript` plugin from the codegen config.
- Drop `preResolveTypes: true` (removed in v6).
- Add `enumType: 'native'` so the call sites that use enum-style
access (`KnowledgeDocType.Answer`, `AgentConfigType.Adviser`, …)
keep compiling — without it, v6 defaults to string-literal unions.
Result:
- `src/graphql/types.ts` shrinks 8819 → 7586 lines, zero duplicate
declarations.
- `KnowledgeDocType`, `AgentConfigType`, etc. remain real TS `enum`s
so `KnowledgeDocType.Answer`-style access keeps working.
- `pnpm run build` clean, lint clean, 531/531 tests passing.
- Vite dev start no longer prints `[PARSE_ERROR] Identifier X has
already been declared`. `/knowledges` (the page that exercises
enum access) loads with 10 rows and zero console errors.
Migration guide:
https://the-guild.dev/graphql/codegen/docs/migration/operations-and-client-preset-from-5-0
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
28 lines
889 B
TypeScript
28 lines
889 B
TypeScript
import type { CodegenConfig } from '@graphql-codegen/cli';
|
|
|
|
const config: CodegenConfig = {
|
|
documents: './graphql-schema.graphql',
|
|
generates: {
|
|
'./src/graphql/types.ts': {
|
|
config: {
|
|
dedupeFragments: true,
|
|
exportFragmentSpreadSubTypes: true,
|
|
apolloReactCommonImportFrom: '@apollo/client/react',
|
|
apolloReactHooksImportFrom: '@apollo/client/react',
|
|
enumType: 'native',
|
|
inlineFragmentTypes: 'combine',
|
|
skipTypename: true,
|
|
useTypeImports: true,
|
|
withHooks: true,
|
|
},
|
|
plugins: ['typescript-operations', 'typescript-react-apollo'],
|
|
},
|
|
},
|
|
hooks: {
|
|
afterOneFileWrite: ['npx prettier --write'],
|
|
},
|
|
schema: '../backend/pkg/graph/schema.graphqls',
|
|
};
|
|
|
|
export default config;
|