Reverted. Simplified resolution

This reverts commit cbb7be90f8.
This commit is contained in:
Walter Barbagallo 2017-07-12 15:23:48 +02:00
parent cbb7be90f8
commit 6a11817192
2 changed files with 7 additions and 19 deletions

View file

@ -18,12 +18,6 @@ const server = micro(
get("/graphql", graphqlHandler),
post("/graphql", graphqlHandler),
get("/graphiql", graphiqlHandler),
get("/noop", (req, res) => {
// Micro router requires at least one 200 route
// or you will always get a 404
return send(res, 200, "");
}),
(req, res) => send(res, 404, "not found"),
),
);

View file

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