Skip to content

Commit 793ff6a

Browse files
authored
Fix json linkprops (#1314)
For some reason, when selected a `json` typed link property, the internal `with` binding of the shape was being skipped, so it would generate incorrect EdgeQL with a missing `with` binding.
1 parent 80f2c89 commit 793ff6a

File tree

6 files changed

+30
-2
lines changed

6 files changed

+30
-2
lines changed

integration-tests/lts/dbschema/default.esdl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module default {
2424

2525
abstract link movie_character {
2626
property character_name -> str;
27+
property meta -> json;
2728
}
2829

2930
abstract type LivingThing {
@@ -85,6 +86,7 @@ module default {
8586
property a -> str;
8687
property b -> str;
8788
property c -> str;
89+
property d -> json;
8890

8991
constraint exclusive on (( .plot_summary, .slug ));
9092
constraint exclusive on (((.a,.b,.c)));
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CREATE MIGRATION m1ikgbe45h3cygjmuxh3ze5rs5d66cqqcq2armmep3r3mjpgezca2a
2+
ONTO m1hbukk7q7j6plwsmgronpimcotrc3uq2i457xronjbre6dt6ie23q
3+
{
4+
ALTER ABSTRACT LINK default::movie_character {
5+
CREATE PROPERTY meta: std::json;
6+
};
7+
ALTER TYPE default::Profile {
8+
CREATE PROPERTY d: std::json;
9+
};
10+
};

integration-tests/lts/interfaces.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export interface test_Profile extends BaseObject {
4545
a?: string | null;
4646
b?: string | null;
4747
c?: string | null;
48+
d?: unknown | null;
4849
}
4950
interface test_Z extends BaseObject {
5051
xy?: W | X | Y | null;

integration-tests/lts/select.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,9 +754,13 @@ describe("select", () => {
754754
test("link properties", async () => {
755755
const query = e.select(e.Movie, () => ({
756756
id: true,
757+
profile: (p) => ({
758+
d: true,
759+
}),
757760
characters: () => ({
758761
name: true,
759762
"@character_name": true,
763+
"@meta": true,
760764
}),
761765
}));
762766

@@ -770,7 +774,11 @@ describe("select", () => {
770774
characters: {
771775
name: string;
772776
"@character_name": string | null;
777+
"@meta": unknown;
773778
}[];
779+
profile: {
780+
d: unknown;
781+
} | null;
774782
}[]
775783
>
776784
>(true);
@@ -1578,6 +1586,7 @@ SELECT __scope_0_defaultPerson {
15781586
test("filter_single composite truple", async () => {
15791587
const query = e.select(e.Profile, () => ({
15801588
slug: true,
1589+
d: true,
15811590
filter_single: {
15821591
a: "adsf",
15831592
b: "adsf",

integration-tests/lts/update.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ describe("update", () => {
303303
test("exclude readonly props", () => {
304304
type updateProfileShape = UpdateShape<(typeof e)["Profile"]>;
305305
tc.assert<
306-
tc.IsExact<keyof updateProfileShape, "plot_summary" | "a" | "b" | "c">
306+
tc.IsExact<
307+
keyof updateProfileShape,
308+
"plot_summary" | "a" | "b" | "c" | "d"
309+
>
307310
>(true);
308311
});
309312

packages/generate/src/syntax/toEdgeQL.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,10 @@ function walkExprTree(
397397

398398
const expr = _expr as SomeExpression;
399399

400-
if ((expr as any).__scopedFrom__ != null) {
400+
if (
401+
(expr as any).__scopedFrom__ != null &&
402+
expr.__kind__ !== ExpressionKind.PathLeaf
403+
) {
401404
// If expr is marked as being a scoped copy of another expr, treat it as
402405
// an opaque reference and don't walk it. The enclosing select/update that
403406
// owns the scope will walk the actual unscoped expr.

0 commit comments

Comments
 (0)