Fix graphql response type

This commit is contained in:
rijkvanzanten
2021-01-14 12:52:57 -05:00
parent 2968a04739
commit d98300d528
3 changed files with 14 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ import { graphqlHTTP } from 'express-graphql';
import { GraphQLService } from '../services';
import { respond } from '../middleware/respond';
import asyncHandler from '../utils/async-handler';
import { cloneDeep } from 'lodash';
const router = Router();
@@ -21,15 +22,14 @@ router.use(
* express' regular `json` function in order to trick express-graphql to
* use the next middleware instead of respond with data directly
*/
const customResponse = {
...res,
json: function (payload: Record<string, any>) {
res.locals.payload = payload;
return next();
},
};
const customResponse = cloneDeep(res);
graphqlHTTP({ schema, graphiql: true })(req, customResponse as Response);
customResponse.json = customResponse.end = function (payload: Record<string, any>) {
res.locals.payload = payload;
return next();
} as any;
graphqlHTTP({ schema, graphiql: true })(req, customResponse);
}),
respond
);