Skip to content

Commit

Permalink
Require path context to be set on 'context' subkey
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Nov 2, 2016
1 parent 8d16905 commit 8cfbd31
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/utils/query-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8cfbd31

Please sign in to comment.