Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions codegen-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
types.ts
121 changes: 121 additions & 0 deletions codegen-test/fixtures/geojson.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Type-level test for the generated GeoJSON codegen type.
//
// Typechecking `types.ts` on its own only proves the emitted type is *valid*
// TypeScript. The GeoJSON precedence bug produced a valid-but-wrong type
// (`Position | Position[]` without parentheses before `[]`), so `tsc` accepted
// it. Assigning real values is what exercises the type: an arrayed geometry's
// coordinates stop being assignable the moment the union isn't grouped.
//
// `input` and `output` are the same union for this scalar; testing one covers both.
import type { Scalars } from '../types';

type GeoJSON = Scalars['GeoJSON']['input'];

// Valid — every geometry from the scalar's own validExamples must be assignable.
const point: GeoJSON = {
type: 'Point',
coordinates: [100.0, 0.0],
};

const multiPoint: GeoJSON = {
type: 'MultiPoint',
coordinates: [
[100.0, 0.0],
[101.0, 1.0],
],
};

const lineString: GeoJSON = {
type: 'LineString',
coordinates: [
[100.0, 0.0],
[101.0, 1.0],
],
};

const multiLineString: GeoJSON = {
type: 'MultiLineString',
coordinates: [
[
[100.0, 0.0],
[101.0, 1.0],
],
[
[102.0, 2.0],
[103.0, 3.0],
],
],
};

const polygon: GeoJSON = {
type: 'Polygon',
coordinates: [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0],
],
],
};

const multiPolygon: GeoJSON = {
type: 'MultiPolygon',
coordinates: [
[
[
[102.0, 2.0],
[103.0, 2.0],
[103.0, 3.0],
[102.0, 3.0],
[102.0, 2.0],
],
],
],
};

const geometryCollection: GeoJSON = {
type: 'GeometryCollection',
geometries: [{ type: 'Point', coordinates: [100.0, 0.0] }],
};

const feature: GeoJSON = {
type: 'Feature',
geometry: { type: 'Point', coordinates: [100.0, 0.0] },
properties: { name: 'Test Point' },
};

const featureCollection: GeoJSON = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: { type: 'Point', coordinates: [100.0, 0.0] },
properties: { name: 'Test Point' },
},
],
};

// Invalid — a single Position is not an array of Positions. The unparenthesized
// bug wrongly accepts this; then the directive is unused and tsc fails, catching
// the bug from the "accepts too much" side and guarding against widening to `any`.
const barePosition: GeoJSON = {
type: 'MultiPoint',
// @ts-expect-error coordinates must be an array of Positions, not one Position
coordinates: [100.0, 0.0],
};

// Reference every binding so unused-local checks stay quiet.
void [
point,
multiPoint,
lineString,
multiLineString,
polygon,
multiPolygon,
geometryCollection,
feature,
featureCollection,
barePosition,
];
8 changes: 8 additions & 0 deletions codegen-test/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{
"name": "codegen-scalars-test",
"scripts": {
"codegen": "graphql-codegen --config codegen.yml",
"test": "yarn codegen && tsc --noEmit -p tsconfig.json"
},
"dependencies": {
"@graphql-codegen/cli": "6.2.1",
"@graphql-codegen/typescript": "5.0.9"
},
"devDependencies": {
"@types/node": "^22.0.0",
"typescript": "^5.5.0"
}
}
9 changes: 8 additions & 1 deletion codegen-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true,
"strict": false,
"moduleResolution": "node",
"lib": ["ESNext", "DOM"],
"types": ["node"],
"baseUrl": ".",
"paths": {
"graphql-scalars": ["../src/index.ts"]
}
},
"files": ["./types.ts"]
"include": ["./types.ts", "./fixtures/**/*.ts"]
}
227 changes: 0 additions & 227 deletions codegen-test/types.ts

This file was deleted.

Loading