首页 > 解决方案 > Gatsby 动态内容和模式拼接

问题描述

我有以下 graphql 查询,该查询在构建时从我用来引入文章数据的 gatsby-node.js 文件中执行。有没有一种方法可以使用 Apollo/Axios 来检索新文章,而无需重建网站,本质上是在两次构建之间为我的网站补水?任何帮助是极大的赞赏!!

我使用 Gatsby v2、Drupal 作为我的 CMS 和 GraphQL。

exports.createPages = ({ graphql, actions }) => {
  const { createPage } = actions;
  const blogTemplate = path.resolve('src/templates/blog-post.js');
  return graphql(`
  {
            blog: allNodeArticle{
        edges {
          node {
            id
            path {
              alias
            }
          }
        }
      }
  `
  ).then(result => {
    if (result.errors) {
      Promise.reject(result.errors);
    }

    // Create blog pages
    result.data.blog.edges.forEach(({ node }) => {
      createPage({
        path: node.path.alias,
        component: blogTemplate,
        context: {
          alias: node.path.alias,
        },
      });
    });
  });
}

我想在新数据可用时合并它,同时保持旧数据完全静态(盖茨比的巨大好处)

标签: javascriptreactjsgatsby

解决方案


推荐阅读