From 814962a5b35e709b0a8ae2bcd337afd484875d44 Mon Sep 17 00:00:00 2001 From: Carson Full Date: Wed, 4 Sep 2024 17:25:59 -0500 Subject: [PATCH] Add failing test for discriminated unions from polymorphic queries via type intersection expr --- integration-tests/lts/dbschema/default.esdl | 4 ++- .../dbschema/migrations/00028-m1cigpn.edgeql | 10 ++++++ integration-tests/lts/paths.test.ts | 4 +-- integration-tests/lts/select.test.ts | 31 ++++++++++++++++++- 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 integration-tests/lts/dbschema/migrations/00028-m1cigpn.edgeql diff --git a/integration-tests/lts/dbschema/default.esdl b/integration-tests/lts/dbschema/default.esdl index 83e7da7d0..d3fb6dc7b 100644 --- a/integration-tests/lts/dbschema/default.esdl +++ b/integration-tests/lts/dbschema/default.esdl @@ -44,7 +44,9 @@ module default { type Hero extending Person { property secret_identity -> str; - property number_of_movies -> int64; + required property number_of_movies -> int64 { + default := 0; + }; multi link villains := . { ); assert.deepEqual( AtLeastOneHero.number_of_movies.__cardinality__, - $.Cardinality.Many, + $.Cardinality.AtLeastOne, ); tc.assert< tc.IsExact< AtLeastOneHero["number_of_movies"]["__cardinality__"], - $.Cardinality.Many + $.Cardinality.AtLeastOne > >(true); diff --git a/integration-tests/lts/select.test.ts b/integration-tests/lts/select.test.ts index 115311f91..1540ec1c7 100644 --- a/integration-tests/lts/select.test.ts +++ b/integration-tests/lts/select.test.ts @@ -362,7 +362,7 @@ describe("select", () => { height: string | null; age: number | null; isAdult: boolean | null; - number_of_movies: number | null; + number_of_movies: number; secret_identity: string | null; } ))[] @@ -1136,6 +1136,35 @@ SELECT __scope_0_defaultPerson { ); }); + test.skip("polymorphic from type intersection", async () => { + const query = e.select(e.Movie.characters, (person) => ({ + heroMovieCount: person.is(e.Hero).number_of_movies, + heroInfo: e.select(person.is(e.Hero), (hero) => ({ + number_of_movies: true, + numMovies: hero.number_of_movies, + })), + })); + type result = $infer; + tc.assert< + tc.IsExact< + result, + ( + | { + __typename: "default::Villain"; + } + | { + __typename: "default::Hero"; + heroMovieCount: number; + heroInfo: { + number_of_movies: number; + numMovies: number; + }; + } + )[] + > + >(false); + }); + test("polymorphic field in nested shape", async () => { const query = e.select(e.Movie, (movie) => ({ title: true,