Skip to content

Commit

Permalink
Fix api for loki (by @freiksenet)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdz committed Jan 28, 2020
1 parent cb83b92 commit 658d07e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/gatsby/src/redux/run-sift.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {
ensureIndexByTypedChain,
getNodesByTypedChain,
addResolvedNodes,
getNode,
getNode: siftGetNode,
} = require(`./nodes`)

/////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -325,27 +325,37 @@ 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<Node>} nodes Should be all nodes of given type(s)
* @param args Legacy api arg, see _runSiftOnNodes
* @param {?function(id: string): Node} getNode
* @returns {Array<Node> | 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,
resolvedFields = {},
nodeTypeNames,
} = args

return _runSiftOnNodes(filter, firstOnly, nodeTypeNames, resolvedFields)
return _runSiftOnNodes(
nodes,
filter,
firstOnly,
nodeTypeNames,
resolvedFields,
getNode
)
}

exports.runSiftOnNodes = runSiftOnNodes
Expand All @@ -358,6 +368,7 @@ exports.runSiftOnNodes = runSiftOnNodes
* @param {boolean} firstOnly
* @param {Array<string>} nodeTypeNames
* @param resolvedFields
* @param {function(id: string): Node} getNode Note: this is different for loki
* @returns {Array<Node> | undefined | null} Collection of results. Collection
* will be limited to 1 if `firstOnly` is true
*/
Expand All @@ -366,7 +377,8 @@ const _runSiftOnNodes = (
filter,
firstOnly,
nodeTypeNames,
resolvedFields
resolvedFields,
getNode
) => {
let siftFilter = getFilters(
liftResolvedFields(toDottedFields(prepareQueryArgs(filter)), resolvedFields)
Expand Down

0 comments on commit 658d07e

Please sign in to comment.