Skip to content

Commit ad11c5a

Browse files
committed
onAfterCall support
1 parent 1af1c37 commit ad11c5a

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ declare module "moleculer-apollo-server" {
8181
fallbackResponse?: any;
8282
};
8383
onBeforeCall?: (ctx: Context, route: any, req: any, res: any) => Promise<any>;
84-
onAfterCall?: (ctx: Context, route: any, req: any, res: any) => Promise<any>;
84+
onAfterCall?: (ctx: Context, route: any, req: any, res: any, data: any) => Promise<any>;
8585
}
8686

8787
export interface ApolloServiceOptions {

src/ApolloServer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ const { renderPlaygroundPage } = require("@apollographql/graphql-playground-html
66
const accept = require("@hapi/accept");
77
const moleculerApollo = require("./moleculerApollo");
88

9-
function send(req, res, statusCode, data, responseType = "application/json") {
9+
async function send(req, res, statusCode, data, responseType = "application/json") {
1010
res.statusCode = statusCode;
1111

1212
const ctx = res.$ctx;
1313
if (!ctx.meta.$responseType) {
1414
ctx.meta.$responseType = responseType;
1515
}
1616

17+
const route = res.$route;
18+
if (route.onAfterCall) {
19+
data = await route.onAfterCall.call(this, ctx, route, req, res, data);
20+
}
21+
22+
1723
const service = res.$service;
1824
service.sendResponse(req, res, data);
1925
}

0 commit comments

Comments
 (0)