Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = async function performQuery(
pgPool,
schema,
query,
variables,
operationName
) {
const queryString = typeof query === "string" ? query : print(query);
return withPostGraphileContext({ pgPool }, async context =>
graphql(
schema, // The schema from `createPostGraphileSchema`
queryString,
null,
{ ...context }, // You can add more to context if you like
variables,
operationName
)
);
};
operationName,
) {
const options = getPGQLOpts();
const queryPlainText = print(query);
const queryCondensed = queryPlainText.replace(/\s\s+/g, ' ').replace(/\n/g, '');
const startTime = Date.now();
let role;
try {
role = decodeJWT(jwtToken).role;
} catch (e) {
role = options.pgDefaultRole || 'anonymous';
}
const value = withPostGraphileContext(
{
...options,
pgPool: getPgPool(),
jwtToken,
},
async (context) => {
const result = graphql(
getSchema(),
queryPlainText,
null,
{ ...context },
variables,
operationName,
).then((data) => {
const totalTime = Date.now() - startTime;
logger.info(`${chalk.green('0 error(s)')} as ${chalk.magenta(role)} in ${chalk.grey(`${totalTime}ms`)} :: ${queryCondensed}`);