title: How do I make GraphQL wait for posts from a separate repo?
body: <p>I have my blog posts in a separate repo from the structure of the site.</p>
  
  <p>This separates commits for the site code from commits for content updates. People could also submit pull requests for error corrections on blog posts.</p>
  
  <p>I am using the NPM package <a href="https://www.npmjs.com/package/download-git-repo" rel="nofollow noreferrer">download-git-repo</a> The first time I run <code>gatsby build</code> it seems the posts aren't loaded before GraphQL is trying to work with them.</p>
  
  <p><code>GraphQLError: Cannot query field "allMarkdownRemark" on type "Query".</code></p>
  
  <p>Running <code>gatsby build</code> a second time does not return an error.</p>
  
  <hr>
  
  <p>Lines 3-5 in gatsby-node.js are my code for importing the blog posts repo.</p>
  
  <p>How can I write this code so that the posts will load before GraphQL is looking for them?</p>
  
  <pre><code>const path = require('path')
  const { createFilePath, createFileNode } = require(`gatsby-source-filesystem`)
  const download = require('download-git-repo')
  
  download('jastuccio/blog-posts', 'src/pages/blog-posts', function(err) {
    console.log(err ? 'Error' : 'Success')
  })
  
  exports.createPages = ({ actions, graphql }) =&gt; {
    const { createPage } = actions
  
    const blogPostTemplate = path.resolve(`src/templates/blog-post.js`)
  
    return new Promise((resolve, reject) =&gt; {
      resolve(
        graphql(`
          {
            allMarkdownRemark(
              sort: { order: DESC, fields: [frontmatter___date] }
              limit: 1000
            ) {
              edges {
                node {
                  fields {
                    slug
                  }
                  frontmatter {
                    title
                  }
                }
              }
            }
          }
        `).then(result =&gt; {
          if (result.errors) {
            console.log(result.errors)
            return reject(result.errors)
          }
  
          const blogTemplate = path.resolve('./src/templates/blog-post.js')
  
          result.data.allMarkdownRemark.edges.forEach(({ node }) =&gt; {
            createPage({
              path: node.fields.slug,
              component: blogTemplate,
              context: {
                slug: node.fields.slug,
              }, // additional data can be passed via context
            })
          })
          return
        })
      )
    })
  }
  
  exports.onCreateNode = ({ node, getNode, actions }) =&gt; {
    const { createNodeField } = actions
    if (node.internal.type === `MarkdownRemark`) {
      const slug = createFilePath({ node, getNode, basePath: `pages` })
      createNodeField({
        node,
        name: `slug`,
        value: slug,
      })
    }
  }
  </code></pre>