I'm using pretender to intercept GraphQL requests so I can mock a GraphQL server and test against it locally. Pretender documentation tells me that I can return a promise resolve, however, It keeps throwing errors at me saying
Error: Pretender intercepted POST /api/graphql but encountered an error: Nothing returned by handler for /api/graphql. Remember to return [status, headers, body]; in your route handler.
And
Uncaught (in promise) Error: Pretender intercepted POST /api/graphql but encountered an error: Nothing returned by handler for /api/graphql. Remember to return [status, headers, body]; in your route handler.
Here's the code where I define the handler. The important thing here is that I want to return the result of mServ.query()..
var server = new Pretender();
server.post('/api/graphql', function(request){
console.log("intercepted");
const query = JSON.parse(request.requestBody);
const variables = query["variables"];
return mServ.query(query["query"], variables).then((result) => { return [200, {"Content-Type": "application/json"}, JSON.stringify(result)]});
});
Aucun commentaire:
Enregistrer un commentaire