Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Consume results inside Transaction functions #508

Merged
merged 1 commit into from
Sep 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,20 @@ export async function neo4jgraphql(

try {
if (isMutation(resolveInfo)) {
result = await session.writeTransaction(tx => {
return tx.run(query, cypherParams);
result = await session.writeTransaction(async tx => {
const result = await tx.run(query, cypherParams);
return extractQueryResult(result, resolveInfo.returnType);
});
} else {
result = await session.readTransaction(tx => {
return tx.run(query, cypherParams);
result = await session.readTransaction(async tx => {
const result = await tx.run(query, cypherParams);
return extractQueryResult(result, resolveInfo.returnType);
});
}
} finally {
session.close();
}
return extractQueryResult(result, resolveInfo.returnType);
return result;
}
}

Expand Down Expand Up @@ -318,15 +320,16 @@ export const assertSchema = ({
const executeQuery = driver => {
const session = driver.session();
return session
.writeTransaction(tx => tx.run(statement))
.then(result => {
if (debug === true) {
const recordsJSON = result.records.map(record => record.toObject());
recordsJSON.sort((lhs, rhs) => lhs.label < rhs.label);
console.table(recordsJSON);
}
return result;
})
.writeTransaction(tx =>
tx.run(statement).then(result => {
if (debug === true) {
const recordsJSON = result.records.map(record => record.toObject());
recordsJSON.sort((lhs, rhs) => lhs.label < rhs.label);
console.table(recordsJSON);
}
return result;
})
)
.finally(() => session.close());
};
return executeQuery(driver).catch(error => {
Expand Down