Skip to content

Commit 3aefb16

Browse files
authored
Fix type error when e.with() wraps unlessConflict() (#1279)
Discussed in Slack with Scott - `insertUnlessConflict` should be `Withable` also There actually weren't any previous tests explicitly testing `insert` is `withable`, but added one anyway for `unlessConflict`.
1 parent 75cde89 commit 3aefb16

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

integration-tests/lts/insert.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,31 @@ describe("insert", () => {
140140
tc.assert<tc.IsExact<typeof r3, { id: string }[]>>(true);
141141
});
142142

143+
test("with wrapping insert .unlessConflict()", async () => {
144+
const dep = e
145+
.insert(e.Hero, {
146+
name: "dependency",
147+
})
148+
.unlessConflict((hero) => ({
149+
on: hero.name,
150+
}));
151+
152+
const query = e.with(
153+
[dep], // test dependency with an unlessConflict() inside it
154+
e.select(e.int16(42)),
155+
);
156+
157+
assert.deepEqual(query.__cardinality__, $.Cardinality.One);
158+
tc.assert<tc.IsExact<(typeof query)["__cardinality__"], $.Cardinality.One>>(
159+
true,
160+
);
161+
162+
const result = await query.run(client);
163+
164+
tc.assert<tc.IsExact<typeof result, 42>>(true);
165+
assert.equal(result, 42);
166+
});
167+
143168
test("nested insert", async () => {
144169
const q1 = e.insert(e.Villain, {
145170
name: e.str("villain"),

packages/generate/src/syntax/with.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type Cardinality, ExpressionKind } from "gel/dist/reflection/index";
22
import type { BaseType, Expression, TypeSet } from "./typesystem";
33
import type { $expr_Select } from "./select";
44
import type { $expr_For } from "./for";
5-
import type { $expr_Insert } from "./insert";
5+
import type { $expr_Insert, $expr_InsertUnlessConflict } from "./insert";
66
import type { $expr_Update } from "./update";
77
import type { $expr_Group } from "./group";
88
import { $assert_single, $expressionify, $unwrap_assert_single } from "./path";
@@ -32,6 +32,7 @@ export type WithableExpression =
3232
| $expr_Select
3333
| $expr_For
3434
| $expr_Insert
35+
| $expr_InsertUnlessConflict
3536
| $expr_Update
3637
| $expr_Group;
3738

0 commit comments

Comments
 (0)