Skip to content

Commit 44f887e

Browse files
committed
Use aql bind vars for table names in the NetworkSubsetter
1 parent b0a391c commit 44f887e

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/utils/queryUtils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ export async function subsetNetwork(
1111
networkName: string,
1212
api: ReturnType<typeof multinetApi>
1313
) {
14-
const aqlQuery = `let nodes = (FOR n in [${nodeTableNames}][**] LIMIT ${subsetAmount} RETURN n) let edges = (FOR e in ${edgeTableName} filter e._from in nodes[**]._id && e._to in nodes[**]._id RETURN e)
14+
const aqlQuery = `let nodes = (FOR n in [${nodeTableNames.map((val, index) => `@@table${index}`).join(', ')}][**] LIMIT ${subsetAmount} RETURN n) let edges = (FOR e in @@edgeTable filter e._from in nodes[**]._id && e._to in nodes[**]._id RETURN e)
1515
RETURN {"nodes": nodes[**], edges}`;
16+
const aqlBindVars: { [key: string]: string } = { '@edgeTable': edgeTableName };
17+
nodeTableNames.forEach((val, index) => {
18+
aqlBindVars[`@table${index}`] = val;
19+
});
1620

1721
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1822
let newAQLNetwork: Network = { nodes: [], edges: []};
1923

2024
try {
21-
newAQLNetwork = (await api.aql(workspaceName, { query: aqlQuery, bind_vars: {} }) as Network[])[0];
25+
newAQLNetwork = (await api.aql(workspaceName, { query: aqlQuery, bind_vars: aqlBindVars }) as Network[])[0];
2226
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2327
} catch (error: any) {
2428
if (error.status === 400) {

0 commit comments

Comments
 (0)