From 658d07ef1e64c45ecc25aac808e8395483acbc25 Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Tue, 28 Jan 2020 12:56:23 +0100 Subject: [PATCH] Fix api for loki (by @freiksenet) --- packages/gatsby/src/redux/run-sift.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/gatsby/src/redux/run-sift.js b/packages/gatsby/src/redux/run-sift.js index 1a324c58b8035..64e7d185f1051 100644 --- a/packages/gatsby/src/redux/run-sift.js +++ b/packages/gatsby/src/redux/run-sift.js @@ -13,7 +13,7 @@ const { ensureIndexByTypedChain, getNodesByTypedChain, addResolvedNodes, - getNode, + getNode: siftGetNode, } = require(`./nodes`) ///////////////////////////////////////////////////////////////////// @@ -325,19 +325,22 @@ const filterWithSift = (filter, firstOnly, nodeTypeNames, resolvedFields) => { filter, firstOnly, nodeTypeNames, - resolvedFields + resolvedFields, + siftGetNode ) } /** * Given a list of filtered nodes and sorting parameters, sort the nodes + * Note: this entry point is used by GATSBY_DB_NODES=loki * * @param {Array} nodes Should be all nodes of given type(s) * @param args Legacy api arg, see _runSiftOnNodes + * @param {?function(id: string): Node} getNode * @returns {Array | undefined | null} Collection of results. Collection * will be limited to 1 if `firstOnly` is true */ -const runSiftOnNodes = (nodes, args) => { +const runSiftOnNodes = (nodes, args, getNode = siftGetNode) => { const { queryArgs: { filter } = { filter: {} }, firstOnly = false, @@ -345,7 +348,14 @@ const runSiftOnNodes = (nodes, args) => { nodeTypeNames, } = args - return _runSiftOnNodes(filter, firstOnly, nodeTypeNames, resolvedFields) + return _runSiftOnNodes( + nodes, + filter, + firstOnly, + nodeTypeNames, + resolvedFields, + getNode + ) } exports.runSiftOnNodes = runSiftOnNodes @@ -358,6 +368,7 @@ exports.runSiftOnNodes = runSiftOnNodes * @param {boolean} firstOnly * @param {Array} nodeTypeNames * @param resolvedFields + * @param {function(id: string): Node} getNode Note: this is different for loki * @returns {Array | undefined | null} Collection of results. Collection * will be limited to 1 if `firstOnly` is true */ @@ -366,7 +377,8 @@ const _runSiftOnNodes = ( filter, firstOnly, nodeTypeNames, - resolvedFields + resolvedFields, + getNode ) => { let siftFilter = getFilters( liftResolvedFields(toDottedFields(prepareQueryArgs(filter)), resolvedFields)