Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
server.all(route, graphqlHTTP(async (req, res) => {
// Acquire a new client for every request.
const client = await pg.connectAsync(pgConfig)
try {
// Start a transaction for our client and set it up.
await client.queryAsync('begin')
// If we have a secret, let’s setup the request transaction.
await setupRequestTransaction(req, client, secret, anonymousRole)
// Make sure we release our client back to the pool once the response has
// finished.
onFinished(res, () => {
// Try to end our session with a commit. If it succeeds, release the
// client back into the pool. If it fails, release the client back into
// the pool, but also report that it failed. We cannot report an error in
// the request at this point because it has finished.
client.queryAsync('commit')
const withClient = fn => async pgConfig => {
const client = await pg.connectAsync(pgConfig)
const result = await fn(client)
client.end()
return result
}