Skip to content

Commit

Permalink
Merge pull request #126 from ajayns/handle-collections
Browse files Browse the repository at this point in the history
Handle collections with seen[path]
  • Loading branch information
datakurre committed Jul 13, 2018
2 parents 5750c34 + 810229b commit d8a7018
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,26 @@ const processNodesUsingRecursion = async (
let nodes = [],
backlinks = {};
const queue = [baseUrl];
const seen = {};

logMessage('Traversing the site and fetching data', showLogs);
while (queue.length > 0) {
const url = queue.shift();
seen[url] = true;

const itemData = await fetchData(url, token, expansions);

const children = itemData.items
? itemData.items.map(item => item['@id'])
: [];
queue.push(...children);
let children = [];
if (itemData.batching) {
const allItems = await fetchAllItems(url, token);
children = allItems.map(item => item['@id']);
} else {
if (itemData.items) {
children = itemData.items.map(item => item['@id']);
}
}

queue.push(...children.filter(child => !seen[child]));

nodes.push(processData(itemData, baseUrl, backlinks, token));
}
Expand Down

0 comments on commit d8a7018

Please sign in to comment.