From b9930a2d811379fc2ad6732da6c77396f2706900 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Wed, 2 Jan 2019 11:46:22 -0700 Subject: [PATCH 1/2] Improve createPages example --- packages/gatsby/src/utils/api-node-docs.js | 72 +++++++++++----------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/packages/gatsby/src/utils/api-node-docs.js b/packages/gatsby/src/utils/api-node-docs.js index 45eaceb95ba15..c8a80fda3633c 100644 --- a/packages/gatsby/src/utils/api-node-docs.js +++ b/packages/gatsby/src/utils/api-node-docs.js @@ -12,49 +12,51 @@ exports.resolvableExtensions = true * * See also [the documentation for the action `createPage`](/docs/actions/#createPage). * @example + * const path = require(`path`) + * * exports.createPages = ({ graphql, actions }) => { * const { createPage } = actions - * return new Promise((resolve, reject) => { - * const blogPostTemplate = path.resolve(`src/templates/blog-post.js`) - * // Query for markdown nodes to use in creating pages. - * resolve( - * graphql( - * ` - * { - * allMarkdownRemark(limit: 1000) { - * edges { - * node { - * fields { - * slug - * } + * const blogPostTemplate = path.resolve(`src/templates/blog-post.js`) + * // Query for markdown nodes to use in creating pages. + * // You can query for whatever data you want to create pages for e.g. + * // products, portfolio items, landing pages, etc. + * graphql(` + * { + * allMarkdownRemark(limit: 1000) { + * edges { + * node { + * fields { + * slug * } * } * } * } - * ` - * ).then(result => { - * if (result.errors) { - * reject(result.errors) - * } - * - * // Create blog post pages. - * result.data.allMarkdownRemark.edges.forEach(edge => { - * createPage({ - * path: `${edge.node.fields.slug}`, // required - * component: blogPostTemplate, - * context: { - * // Add optional context data. Data can be used as - * // arguments to the page GraphQL query. - * // - * // The page "path" is always available as a GraphQL - * // argument. - * }, - * }) - * }) + * } + * `).then(result => { + * if (result.errors) { + * reject(result.errors) + * } * - * return + * // Create blog post pages. + * result.data.allMarkdownRemark.edges.forEach(edge => { + * createPage({ + * // Path for this page — required + * path: `${edge.node.fields.slug}`, + * component: blogPostTemplate, + * context: { + * // Add optional context data to be inserted + * // as props into the page component.. + * // + * // The context data can also be used as + * // arguments to the page GraphQL query. + * // + * // The page "path" is always available as a GraphQL + * // argument. + * }, * }) - * ) + * }) + * + * return * }) * } */ From 7f65af9e5ddf987333f15d65b391ddb15a10bd7f Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Wed, 2 Jan 2019 11:55:55 -0700 Subject: [PATCH 2/2] Fixes from @dschau's review --- packages/gatsby/src/utils/api-node-docs.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/gatsby/src/utils/api-node-docs.js b/packages/gatsby/src/utils/api-node-docs.js index c8a80fda3633c..db7a6f3984813 100644 --- a/packages/gatsby/src/utils/api-node-docs.js +++ b/packages/gatsby/src/utils/api-node-docs.js @@ -20,7 +20,7 @@ exports.resolvableExtensions = true * // Query for markdown nodes to use in creating pages. * // You can query for whatever data you want to create pages for e.g. * // products, portfolio items, landing pages, etc. - * graphql(` + * return graphql(` * { * allMarkdownRemark(limit: 1000) { * edges { @@ -34,7 +34,7 @@ exports.resolvableExtensions = true * } * `).then(result => { * if (result.errors) { - * reject(result.errors) + * throw result.errors * } * * // Create blog post pages. @@ -55,8 +55,6 @@ exports.resolvableExtensions = true * }, * }) * }) - * - * return * }) * } */