Skip to content

Commit

Permalink
Add error handler for create mutations also
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Sep 22, 2017
1 parent 196ab27 commit 1dc5e39
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/graphile-build-pg/src/plugins/PgMutationCreatePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,24 @@ export default (function PgMutationCreatePlugin(
) values(${sql.join(sqlValues, ", ")})`
: sql.fragment`default values`} returning *`;

const { rows: [row] } = await viaTemporaryTable(
pgClient,
sql.identifier(table.namespace.name, table.name),
mutationQuery,
insertedRowAlias,
query
);
let row;
try {
await pgClient.query("SAVEPOINT graphql_mutation");
const result = await viaTemporaryTable(
pgClient,
sql.identifier(table.namespace.name, table.name),
mutationQuery,
insertedRowAlias,
query
);
row = result.rows[0];
await pgClient.query("RELEASE SAVEPOINT graphql_mutation");
} catch (e) {
await pgClient.query(
"ROLLBACK TO SAVEPOINT graphql_mutation"
);
throw e;
}
return {
clientMutationId: input.clientMutationId,
data: row,
Expand Down

0 comments on commit 1dc5e39

Please sign in to comment.