Added internal GraphQL client, using GraphQL for scenes API.
This commit is contained in:
24
src/web/graphql.js
Normal file
24
src/web/graphql.js
Normal 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 };
|
||||
Reference in New Issue
Block a user