Skip to content

Revive the codegen typecheck harness#3092

Open
ifeanyi-ugwu wants to merge 3 commits into
graphql-hive:masterfrom
ifeanyi-ugwu:chore/codegen-test-revive
Open

Revive the codegen typecheck harness#3092
ifeanyi-ugwu wants to merge 3 commits into
graphql-hive:masterfrom
ifeanyi-ugwu:chore/codegen-test-revive

Conversation

@ifeanyi-ugwu

Copy link
Copy Markdown
Contributor

Revives the dormant codegen-test/ harness to regenerate the scalar types and typecheck them in CI, and adds a value-assignment fixture proving the generated GeoJSON type accepts real geometries.

The harness was dead code: its committed types.ts referenced graphql-scalars type exports that never existed, and nothing ran it. It now runs graphql-codegen + tsc --noEmit under the root test script, with the generated file gitignored so a stale copy can't recur. This guards that every scalar's codegenScalarType emits valid TypeScript.

A plain typecheck proves the emitted types are valid TS, not that they're correct — the GeoJSON precedence bug (#3089) produced a valid-but-wrong nested type that tsc accepted. codegen-test/fixtures/geojson.ts closes that gap: it assigns each GeoJSON geometry to the generated type, and the arrayed geometries (MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon) fail to assign if the Position union isn't parenthesized.

Includes #3089's one-line fix so the branch typechecks standalone; that commit rebases out once #3089 merges. Touches the root test script, which changes what CI runs.

codegen-test/ was dead code: its committed types.ts referenced `graphql-scalars`
type exports that never existed, and nothing ran it — no script, no workflow.

It now regenerates types.ts, typechecks the output (`yarn codegen && tsc
--noEmit`), and runs under `yarn test` for CI coverage. The generated file is
gitignored, since a stale committed copy is what rotted here before. This guards
that every scalar's codegenScalarType is valid TypeScript.
generatePositionType() returned an unparenthesized union, so arrayed
usages (`${generatePositionType()}[]`) applied `[]` to only the second
member: `[number, number] | [number, number, number][]` instead of
`([number, number] | [number, number, number])[]`. The codegenScalarType
string emitted to GraphQL Codegen consumers was therefore wrong for
MultiPoint, LineString, MultiLineString, Polygon and MultiPolygon (every
geometry whose coordinates are arrays of positions).
Typechecking the generated types.ts on its own only proves the emitted
type is valid TypeScript. A precedence error in a scalar's codegen type —
such as an unparenthesized `Position | Position[]` before `[]` — produces
a valid but wrong type that `tsc --noEmit` accepts without complaint.

Assigning each of GeoJSON's valid examples to the generated type exercises
it: an arrayed geometry's coordinates stop being assignable when the union
isn't grouped. A negative `@ts-expect-error` case guards the reverse,
failing if the type widens enough to accept a bare Position.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant