From f6382a58f5e36327c78b61583f02482d573f5a06 Mon Sep 17 00:00:00 2001 From: Dijana Pavlovic Date: Tue, 9 Jul 2024 19:35:55 +0200 Subject: [PATCH] Remove from object shape keys with value never (#1051) * Remove from object shape keys with value never * Fix failing test & add 2 more tests --- integration-tests/lts/dbschema/default.esdl | 1 + .../dbschema/migrations/00026-m1wb2dg.edgeql | 7 ++++ integration-tests/lts/interfaces.test.ts | 1 + integration-tests/lts/objectTypes.test.ts | 1 + integration-tests/lts/select.test.ts | 37 ++++++++++++++++++- packages/generate/src/syntax/typesystem.ts | 4 +- 6 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 integration-tests/lts/dbschema/migrations/00026-m1wb2dg.edgeql diff --git a/integration-tests/lts/dbschema/default.esdl b/integration-tests/lts/dbschema/default.esdl index 0c3f1595a..ae8c30b0f 100644 --- a/integration-tests/lts/dbschema/default.esdl +++ b/integration-tests/lts/dbschema/default.esdl @@ -31,6 +31,7 @@ module default { constraint exclusive; }; property height -> decimal; + property isAdult -> bool; } type Villain extending Person { diff --git a/integration-tests/lts/dbschema/migrations/00026-m1wb2dg.edgeql b/integration-tests/lts/dbschema/migrations/00026-m1wb2dg.edgeql new file mode 100644 index 000000000..058f175b7 --- /dev/null +++ b/integration-tests/lts/dbschema/migrations/00026-m1wb2dg.edgeql @@ -0,0 +1,7 @@ +CREATE MIGRATION m1wb2dgjeppqex272zwvqnsdfzdvvppub4iwa5vaxu3xxigyjlruka + ONTO m1rjlewu5fimvn4lf4xguullcbvlttuxmtxyl4yz4dmsbyw5shva7a +{ + ALTER TYPE default::Person { + CREATE PROPERTY isAdult: std::bool; + }; +}; diff --git a/integration-tests/lts/interfaces.test.ts b/integration-tests/lts/interfaces.test.ts index 27ec49a12..e949186e8 100644 --- a/integration-tests/lts/interfaces.test.ts +++ b/integration-tests/lts/interfaces.test.ts @@ -24,6 +24,7 @@ export interface BaseObject { export interface test_Person extends BaseObject { name: string; height?: string | null; + isAdult?: boolean | null; } export interface test_Movie extends BaseObject { characters: test_Person[]; diff --git a/integration-tests/lts/objectTypes.test.ts b/integration-tests/lts/objectTypes.test.ts index d04799a24..20806c4fb 100644 --- a/integration-tests/lts/objectTypes.test.ts +++ b/integration-tests/lts/objectTypes.test.ts @@ -206,6 +206,7 @@ describe("object types", () => { id: true, name: true, height: true, + isAdult: true, secret_identity: true, number_of_movies: true, }); diff --git a/integration-tests/lts/select.test.ts b/integration-tests/lts/select.test.ts index eeaa867e5..c82fc93c6 100644 --- a/integration-tests/lts/select.test.ts +++ b/integration-tests/lts/select.test.ts @@ -295,7 +295,6 @@ describe("select", () => { id: string; secret_identity: string | null; nemesis: { id: string; computable: 1234 } | null; - computable: never; }[] > >(true); @@ -336,6 +335,7 @@ describe("select", () => { { name: string; height: string | null; + isAdult: boolean | null; number_of_movies: number | null; secret_identity: string | null; }[] @@ -1524,4 +1524,39 @@ SELECT __scope_0_defaultPerson { })); await query.run(client); }); + + test("False shape pointers are not returned", () => { + const q = e.select(e.Movie, () => ({ + title: true, + rating: true, + genre: false, + })); + + tc.assert< + tc.IsExact< + $infer, + { + title: string; + rating: number | null; + }[] + > + >(true); + }); + + test("Select assignment works", () => { + const q = e.select(e.Person, () => ({ + name: true, + isAdult: e.bool(false), + })); + + tc.assert< + tc.IsExact< + $infer, + { + name: string; + isAdult: false; + }[] + > + >(true); + }); }); diff --git a/packages/generate/src/syntax/typesystem.ts b/packages/generate/src/syntax/typesystem.ts index fa6df6aac..6a7c7af56 100644 --- a/packages/generate/src/syntax/typesystem.ts +++ b/packages/generate/src/syntax/typesystem.ts @@ -363,7 +363,7 @@ export type computeObjectShape< > = typeutil.flatten< keyof Shape extends never ? { id: string } - : { + : typeutil.stripNever<{ [k in keyof Shape]: Shape[k] extends $expr_PolyShapeElement< infer PolyType, infer ShapeEl @@ -385,7 +385,7 @@ export type computeObjectShape< : [k] extends [keyof Pointers] ? shapeElementToTs : never; - } + }> >; export type PrimitiveType =