Skip to content

docs(gatsby): improve createPages example #10777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 2, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 37 additions & 35 deletions packages/gatsby/src/utils/api-node-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to return here? It doesn't really matter either way, but it doesn't hurt

* {
* 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* reject(result.errors)
* return Promise.reject(result.errors)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this should be a throw, yikes, didn't read this very closely.

* }
*
* 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just drop this? The flow ends here anyways, particularly if we return the graphql call above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* })
* }
*/
Expand Down