mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 10:11:40 -05:00
parent
cbb7be90f8
commit
6a11817192
2 changed files with 7 additions and 19 deletions
|
@ -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"),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue