mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 10:11:40 -05:00
Using await on graphiql handler
This commit is contained in:
parent
2479911906
commit
cbb7be90f8
1 changed files with 13 additions and 7 deletions
|
@ -61,16 +61,22 @@ export interface MicroGraphiQLOptionsFunction {
|
|||
}
|
||||
|
||||
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 || {};
|
||||
GraphiQL.resolveGraphiQLString(query, options, req).then(graphiqlString => {
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.write(graphiqlString);
|
||||
res.end();
|
||||
}, error => {
|
||||
let graphiqlString;
|
||||
|
||||
try {
|
||||
graphiqlString = await GraphiQL.resolveGraphiQLString(query, options, req);
|
||||
} catch (error) {
|
||||
res.statusCode = 500;
|
||||
res.write(error.message);
|
||||
res.end();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.write(graphiqlString);
|
||||
res.end();
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue