javascript - 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,
},
});
});
});
}
我想在新数据可用时合并它,同时保持旧数据完全静态(盖茨比的巨大好处)
解决方案
推荐阅读
- reactjs - React Hook useEffect 在根据当前值更新状态时缺少依赖项
- discord - 无法注册斜线命令。获取丢失访问错误
- c++ - std::forward 不允许接受左值
- python - 将一个列表中的项目映射到另一个列表中的项目
- c - C - Execv - 不兼容的指针类型
- google-cloud-platform - 如何授予对 GCP Firestore 中 storage.buckets.list 的访问权限?
- mongodb - MongoDB 聚合 addField 包含当前对象在数组查询中的位置
- ios - 将视频分割成 30 秒的块 Ios swift 5
- javascript - Angular:使用 Redux 从 Firebase 中删除单个元素
- javascript - 如何使用 Javascript 验证基于模式的 JSON 请求