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