Skip to content

Commit a585226

Browse files
committed
Avoid mutating in defaultsDeep calls and use proper key in called action params
1 parent f55ae66 commit a585226

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/service.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,11 @@ module.exports = function(mixinOptions) {
154154
if (context.dataLoaders.has(dataLoaderMapKey)) {
155155
dataLoader = context.dataLoaders.get(dataLoaderMapKey);
156156
} else {
157+
const batchedParamKey = rootParams[dataLoaderRootKey];
157158
dataLoader = this.buildDataLoader(
158159
context.ctx,
159160
actionName,
160-
dataLoaderRootKey,
161+
batchedParamKey,
161162
staticParams,
162163
args
163164
);
@@ -179,9 +180,10 @@ module.exports = function(mixinOptions) {
179180
_.set(params, rootParams[key], _.get(root, key))
180181
);
181182
}
183+
182184
return await context.ctx.call(
183185
actionName,
184-
_.defaultsDeep(args, params, staticParams)
186+
_.defaultsDeep({}, args, params, staticParams)
185187
);
186188
}
187189
} catch (err) {
@@ -206,7 +208,7 @@ module.exports = function(mixinOptions) {
206208
getDataLoaderMapKey(actionName, staticParams, args) {
207209
if (Object.keys(staticParams).length > 0 || Object.keys(args).length > 0) {
208210
// create a unique hash of the static params and the arguments to ensure a unique DataLoader instance
209-
const actionParams = _.defaultsDeep(args, staticParams);
211+
const actionParams = _.defaultsDeep({}, args, staticParams);
210212
const paramsHash = hash(actionParams);
211213
return `${actionName}:${paramsHash}`;
212214
}
@@ -227,7 +229,7 @@ module.exports = function(mixinOptions) {
227229
buildDataLoader(ctx, actionName, batchedParamKey, staticParams, args) {
228230
const batchLoadFn = keys => {
229231
const rootParams = { [batchedParamKey]: keys };
230-
return ctx.call(actionName, _.defaultsDeep(args, rootParams, staticParams));
232+
return ctx.call(actionName, _.defaultsDeep({}, args, rootParams, staticParams));
231233
};
232234

233235
if (dataLoaderOptions.has(actionName)) {

0 commit comments

Comments
 (0)