Skip to content

Commit

Permalink
feat: run queries in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Bell committed Nov 16, 2022
1 parent eff3329 commit 5f3a5f1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,20 @@ export const queriesBuilder = async (
context,
queries: { [key: string]: Query }
) => {
for (let key of Object.keys(queries)) {
if (context.variables[`\$${key}`]) {
const build = async(key: string) => {
if (context.variables[`\$${key}`]) {
console.log(`\n⚠️ WARNING: the key "$${key}" is being reassigned`);
}
context.variables[`\$${key}`] = await sendQuery(context, key, queries[key]);
};

// Run queries in parallel, provided no arguments reference variables
const variables = Object.entries(queries).some(([key, query]) =>
query.args.some(arg => typeof(arg) === 'string' && arg.startsWith("$")));
if (!variables)
await Promise.all(Object.keys(queries).map(build));
else {
for (let key of Object.keys(queries))
await build(key);
}
};

0 comments on commit 5f3a5f1

Please sign in to comment.