Skip to content

Commit

Permalink
Use aql bind vars for table names in the NetworkSubsetter
Browse files Browse the repository at this point in the history
  • Loading branch information
JackWilb committed Feb 2, 2023
1 parent b0a391c commit 44f887e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/utils/queryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ export async function subsetNetwork(
networkName: string,
api: ReturnType<typeof multinetApi>
) {
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)
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)
RETURN {"nodes": nodes[**], edges}`;
const aqlBindVars: { [key: string]: string } = { '@edgeTable': edgeTableName };
nodeTableNames.forEach((val, index) => {
aqlBindVars[`@table${index}`] = val;
});

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

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

0 comments on commit 44f887e

Please sign in to comment.