Using await on graphiql handler

This commit is contained in:
Walter Barbagallo 2017-07-10 10:36:48 +02:00
parent 2479911906
commit cbb7be90f8

View file

@ -61,16 +61,22 @@ export interface MicroGraphiQLOptionsFunction {
} }
export function microGraphiql(options: GraphiQL.GraphiQLData | MicroGraphiQLOptionsFunction): RequestHandler { export function microGraphiql(options: GraphiQL.GraphiQLData | MicroGraphiQLOptionsFunction): RequestHandler {
return (req: IncomingMessage, res: ServerResponse) => { return async (req: IncomingMessage, res: ServerResponse) => {
const query = req.url && url.parse(req.url, true).query || {}; const query = req.url && url.parse(req.url, true).query || {};
GraphiQL.resolveGraphiQLString(query, options, req).then(graphiqlString => { let graphiqlString;
res.setHeader('Content-Type', 'text/html');
res.write(graphiqlString); try {
res.end(); graphiqlString = await GraphiQL.resolveGraphiQLString(query, options, req);
}, error => { } catch (error) {
res.statusCode = 500; res.statusCode = 500;
res.write(error.message); res.write(error.message);
res.end(); res.end();
}); return;
}
res.setHeader('Content-Type', 'text/html');
res.write(graphiqlString);
res.end();
return;
}; };
} }