forked from DebaucheryLibrarian/traxxx
25 lines
598 B
JavaScript
25 lines
598 B
JavaScript
|
'use strict';
|
||
|
|
||
|
const { withPostGraphileContext } = require('postgraphile');
|
||
|
const { graphql } = require('graphql');
|
||
|
|
||
|
const pg = require('./postgraphile');
|
||
|
const logger = require('../logger')(__filename);
|
||
|
|
||
|
async function query(graphqlQuery, params) {
|
||
|
return withPostGraphileContext(pg, async (context) => {
|
||
|
const schema = await pg.getGraphQLSchema();
|
||
|
const result = await graphql(schema, graphqlQuery, null, context, params);
|
||
|
|
||
|
if (result.errors?.length > 0) {
|
||
|
logger.error(result.errors);
|
||
|
|
||
|
throw result.errors[0];
|
||
|
}
|
||
|
|
||
|
return result.data;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
module.exports = { graphql: query };
|