Added internal GraphQL client, using GraphQL for scenes API.

This commit is contained in:
DebaucheryLibrarian
2021-02-27 03:52:27 +01:00
parent 162e5c2181
commit 2deed3a7eb
6 changed files with 220 additions and 108 deletions

24
src/web/graphql.js Normal file
View File

@@ -0,0 +1,24 @@
'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 };