Skip to content

Commit bc03c06

Browse files
committed
Fix support for mixed value-type arrays
While refactoring this code, I had assumed that an array value would contain either pointers or primitives, but we allow mixed arrays. Trying to use `include` to preload pointers in such an array shouldn't drop the other elements from the array.
1 parent 60750b4 commit bc03c06

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/RestQuery.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -960,14 +960,14 @@ function replacePointers(object, path, replace) {
960960
const searchPath = path.slice(0, -1);
961961
const attrName = path[path.length - 1];
962962
traverse(object, searchPath, node => {
963-
// this could be either a pointer or an array of pointers
964-
const pointerOrPointers = node[attrName];
965-
if (pointerOrPointers instanceof Array) {
966-
node[attrName] = pointerOrPointers
967-
.map(pointer => pointer && replace[pointer.objectId])
968-
.filter(pointer => pointer || pointer === null);
969-
} else if (pointerOrPointers && pointerOrPointers.__type === 'Pointer') {
970-
node[attrName] = replace[pointerOrPointers.objectId];
963+
const value = node[attrName];
964+
if (value instanceof Array) {
965+
// the value can be a mixed array; be careful to only replace pointers!
966+
node[attrName] = value
967+
.map(obj => obj && obj.__type === 'Pointer' ? replace[obj.objectId] : obj)
968+
.filter(pointer => typeof pointer !== 'undefined');
969+
} else if (value && value.__type === 'Pointer') {
970+
node[attrName] = replace[value.objectId];
971971
}
972972
});
973973
}

0 commit comments

Comments
 (0)