Skip to content

Commit

Permalink
Fix existingItem in updateManyMutation hooks (#3241)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Jul 8, 2020
1 parent 5ad84cc commit 61cdafe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/famous-pumpkins-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystonejs/keystone': patch
---

Fixed a bug where `existingItem` had the wrong value in hooks during an `updateManyMutation`.
4 changes: 3 additions & 1 deletion packages/keystone/lib/ListTypes/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
flatten,
zipObj,
createLazyDeferred,
arrayToObject,
} = require('@keystonejs/utils');
const { parseListAccess } = require('@keystonejs/access-control');
const { logger } = require('@keystonejs/logger');
Expand Down Expand Up @@ -833,9 +834,10 @@ module.exports = class List {
const access = await this.checkListAccess(context, data, operation, extraData);

const existingItems = await this.getAccessControlledItems(ids, access);
const existingItemsById = arrayToObject(existingItems, 'id');

const itemsToUpdate = zipObj({
existingItem: existingItems,
existingItem: ids.map(id => existingItemsById[id]),
id: ids, // itemId is taken from here in checkFieldAccess
data: data.map(d => d.data),
});
Expand Down

0 comments on commit 61cdafe

Please sign in to comment.