Skip to content

Commit

Permalink
onAfterCall support
Browse files Browse the repository at this point in the history
  • Loading branch information
ealejandromt committed Mar 11, 2021
1 parent 1af1c37 commit ad11c5a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ declare module "moleculer-apollo-server" {
fallbackResponse?: any;
};
onBeforeCall?: (ctx: Context, route: any, req: any, res: any) => Promise<any>;
onAfterCall?: (ctx: Context, route: any, req: any, res: any) => Promise<any>;
onAfterCall?: (ctx: Context, route: any, req: any, res: any, data: any) => Promise<any>;
}

export interface ApolloServiceOptions {
Expand Down
8 changes: 7 additions & 1 deletion src/ApolloServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ const { renderPlaygroundPage } = require("@apollographql/graphql-playground-html
const accept = require("@hapi/accept");
const moleculerApollo = require("./moleculerApollo");

function send(req, res, statusCode, data, responseType = "application/json") {
async function send(req, res, statusCode, data, responseType = "application/json") {
res.statusCode = statusCode;

const ctx = res.$ctx;
if (!ctx.meta.$responseType) {
ctx.meta.$responseType = responseType;
}

const route = res.$route;
if (route.onAfterCall) {
data = await route.onAfterCall.call(this, ctx, route, req, res, data);
}


const service = res.$service;
service.sendResponse(req, res, data);
}
Expand Down

0 comments on commit ad11c5a

Please sign in to comment.