Skip to content

Commit 7559df4

Browse files
author
Paul Korzhyk
committed
Merge branch 'one-to-one'
2 parents 39023b9 + 02d0132 commit 7559df4

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

client/src/e2etests/oneToOne.test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import puppeteer from "puppeteer";
2+
3+
import {
4+
easyUid,
5+
createHttpClient,
6+
createTestTab,
7+
setupBrowser,
8+
typeAndRun,
9+
waitForEditor,
10+
waitForActiveTab,
11+
waitForElement,
12+
} from "./puppetHelpers";
13+
14+
let browser = null;
15+
16+
beforeAll(async () => {
17+
browser = await setupBrowser();
18+
});
19+
20+
afterAll(async () => browser && (await browser.close()));
21+
22+
test("Should draw one to one nodes", async () => {
23+
const page = await createTestTab(browser);
24+
25+
await waitForEditor(page);
26+
27+
const testId = `testRun${easyUid()}`;
28+
29+
await createHttpClient().alter({ schema: `${testId}: uid .` });
30+
await createHttpClient()
31+
.newTxn()
32+
.mutate({
33+
setJson: {
34+
[testId + "_name"]: "Alice",
35+
[testId]: {
36+
[testId + "_name"]: "Bob",
37+
},
38+
},
39+
commitNow: true,
40+
});
41+
42+
await typeAndRun(
43+
page,
44+
`{
45+
query(func: has(${testId})) {
46+
uid
47+
${testId} { uid }
48+
`,
49+
);
50+
51+
const summarySelector = ".graph-overlay .title";
52+
await waitForElement(page, summarySelector);
53+
54+
await expect(
55+
page.$eval(summarySelector, el => el.textContent),
56+
).resolves.toBe("Showing 2 nodes and 1 edges");
57+
});

client/src/lib/graph.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,13 @@ export class GraphParser {
8686
addResponseToQueue = (response, expansionNode = "FromResponse") => {
8787
response = cloneDeep(response);
8888

89-
Object.entries(response).forEach(([key, block], index) =>
89+
Object.entries(response).forEach(([key, block]) =>
9090
block.forEach(node =>
9191
this.queue.push({
9292
node,
9393
src: {
9494
id: "",
9595
pred: key,
96-
index,
9796
expansionNode,
9897
},
9998
}),
@@ -163,17 +162,30 @@ export class GraphParser {
163162
typeof val[0] === "object"
164163
) {
165164
// These are child nodes, lets add them to the queue.
166-
val.map((x, index) =>
165+
val.map(x =>
167166
this.queue.push({
168167
node: x,
169168
src: {
170169
pred: prop,
171170
id: uid,
172-
index,
173171
expansionNode: obj.src.expansionNode,
174172
},
175173
}),
176174
);
175+
} else if (
176+
typeof val === "object" &&
177+
val &&
178+
typeof val.uid === "string"
179+
) {
180+
// This is a one to one relationship in v1.1.
181+
this.queue.push({
182+
node: val,
183+
src: {
184+
pred: prop,
185+
id: uid,
186+
expansionNode: obj.src.expansionNode,
187+
},
188+
});
177189
} else {
178190
properties.attrs[prop] = val;
179191
}

0 commit comments

Comments
 (0)