Skip to content

Commit

Permalink
fix(hooks): add arguments to post hooks too
Browse files Browse the repository at this point in the history
  • Loading branch information
Andras Toth committed Dec 3, 2015
1 parent 63d8263 commit d083b76
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,16 @@ const hooks = {
}
},
// singular: {
// pre: (next, root, args, {rootValue}) => next(),
// post: (next, value) => next()
// pre: (next, root, args, context) => next(),
// post: (next, value, args, context) => next()
// },
// plural: {
// pre: (next, root, args, {rootValue}) => next(),
// post: (next, value) => next()
// pre: (next, root, args, context) => next(),
// post: (next, value, args, context) => next()
// },
// mutation: {
// pre: (next, args, {rootValue}) => next(),
// post: (next, value) => next()
// pre: (next, args, context) => next(),
// post: (next, value, args, context) => next()
// }
};
const schema = getSchema([User], {hooks});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"chai": "^3.4.0",
"chai-subset": "^1.1.0",
"co-mocha": "^1.1.2",
"eslint": "^1.10.2",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^1.0.2",
"graphql": "^0.4.12",
"mocha": "^2.3.3",
Expand Down
9 changes: 6 additions & 3 deletions src/utils/Middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ export default class Middleware {
compose(...args) {
let lastResult;
return reduceRight(this.middleware, (mw, fn) => {
const next = async (result) => {
lastResult = result;
await mw.call(this, result);
const next = async (...result) => {
if (!result.length) {
result = args;
}
lastResult = result[0];
await mw.call(this, ...result);
};
return async (...result) => {
if (!result.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function addHooks(resolver, {pre, post} = {}) {
await preMiddleware.compose(...args);
const postMiddleware = new Middleware(post);
const result = await resolver(...args);
return await postMiddleware.compose(result) || result;
return await postMiddleware.compose(result, ...args) || result;
};
}

Expand Down

0 comments on commit d083b76

Please sign in to comment.