How to use the postgraphile.withPostGraphileContext function in postgraphile

To help you get started, we’ve selected a few postgraphile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphile / gatsby-source-pg / lib / performQuery.js View on Github external
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
    )
  );
};
github storyforj / fervor / src / server / graphql / performQuery.js View on Github external
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}`);

postgraphile

A GraphQL schema created by reflection over a PostgreSQL schema 🐘 (previously known as PostGraphQL)

MIT
Latest version published 1 year ago

Package Health Score

78 / 100
Full package analysis