Context params moved earlier

This commit is contained in:
Don Masakayan 2019-10-19 19:33:06 +08:00
parent aa91ca7a96
commit 93319d8c47

View File

@ -176,6 +176,19 @@ module.exports = {
return async (obj, options, graphqlCtx) => {
const { context } = graphqlCtx;
if (options.input && options.input.where) {
context.params = Query.convertToParams(options.input.where || {});
} else {
context.params = {};
}
if (options.input && options.input.data) {
context.request.body = options.input.data || {};
} else {
context.request.body = options;
}
// Hack to be able to handle permissions for each query.
const ctx = Object.assign(_.clone(context), {
request: Object.assign(_.clone(context.request), {
@ -183,18 +196,6 @@ module.exports = {
}),
});
if (options.input && options.input.where) {
ctx.params = Query.convertToParams(options.input.where || {});
} else {
ctx.params = {};
}
if (options.input && options.input.data) {
ctx.request.body = options.input.data || {};
} else {
ctx.request.body = options;
}
// Execute policies stack.
const policy = await compose(policiesFn)(ctx);
@ -216,7 +217,7 @@ module.exports = {
const normalizedName = _.toLower(name);
if (isController) {
const values = await resolver.call(null, ctx);
const values = await resolver.call(null, context);
if (ctx.body) {
return options.input