From 8cfbd31b7e1fb144c71ec024505f1da8ed73cc71 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Tue, 1 Nov 2016 17:12:28 -0700 Subject: [PATCH] Require path context to be set on 'context' subkey --- lib/utils/query-runner.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/utils/query-runner.js b/lib/utils/query-runner.js index 5e7bb38a7763c..90ccda5d656d1 100644 --- a/lib/utils/query-runner.js +++ b/lib/utils/query-runner.js @@ -302,13 +302,23 @@ const q = queue(({ file, graphql, directory }, callback) => { // Run queries for each page component. console.time(`graphql query time`) Promise.all(paths.map((pathInfo) => { - return graphql(query, pathInfo) + let pathContext + // Mixin the path context to the top-level. + // TODO do runtime check that user not passing in key that conflicts + // w/ top-level keys e.g. path or component. + if (pathInfo.context) { + pathContext = { ...pathInfo, ...pathInfo.context } + } else { + pathContext = { ...pathInfo } + } + return graphql(query, pathContext) .catch(error => console.log(`graphql error`, error)) .then(result => { if (result.errors) { console.log(`graphql errors`, result.errors) } - // Combine the result with the pathInfo. + // Combine the result with the path context. + result.pathContext = pathInfo.context const clonedResult = { ...result } result.pathContext = pathInfo