graphile-test
Version:
PostGraphile Testing
31 lines (30 loc) • 874 B
JavaScript
import { runGraphQLInContext } from './context';
import { createPostGraphileSchema } from 'postgraphile';
import { getGraphileSettings } from 'graphile-settings';
export const GraphQLTest = (input, conn) => {
const { schemas, authRole } = input;
let schema;
let options;
const pgPool = conn.manager.getPool(conn.pg.config);
const setup = async () => {
options = getGraphileSettings({ graphile: { schema: schemas } });
schema = await createPostGraphileSchema(pgPool, schemas, options);
};
const teardown = async () => { };
const query = async (opts) => {
return await runGraphQLInContext({
input,
schema,
options,
authRole,
pgPool,
conn,
...opts
});
};
return {
setup,
teardown,
query
};
};