Gatsby : How to query result of transformer plugin?

标签 gatsby

出于学习目的,我编写了一个反转节点内容的 Gatsby 转换器。我将它与 gatsby-source-filesystem 一起使用,仅在 .test 文件上运行:

const crypto = require(`crypto`)

module.exports = function onCreateNode({ node, loadNodeContent, boundActionCreators }) {
  const { createNode, createParentChildLink } = boundActionCreators;

  if (node.extension !== 'test') {
    return;
  }

  const nodeContent = loadNodeContent(node);
  const nodeContentRev = nodeContent.split('').reverse().join('');
  const contentDigest = crypto
      .createHash(`md5`)
      .update(JSON.stringify(nodeContent))
      .digest(`hex`);
  const RevNode = {
    'contentRev': nodeContentRev,

    id: '9087657865-just-something-here-for-now',
    parent: null,
    children: [],
    internal: {
      type: 'Rev',
      contentDigest,
      content,
    },
  };

  createNode(RevNode);
}

不幸的是,我对 Gatsby 还是很陌生,所以我正在努力弄清楚这是否有效。看看官方的转换器,他们不仅实现了gatsby-node.js(我有),而且还实现了extend-node-type.js,但我找不到关于此的任何文档。

如何查询转换器的结果?

最佳答案

假设您首先验证以下内容:

  1. 您的代码被加载并运行而没有引发异常。如果不是,请先使用 console.log 消息或调试器验证这一点。
  2. 您的源插件已正确配置并且正在其配置目录中获取文件。

假设两者均已验证并且转换器插件已加载并正常运行,您将在 gatsby 的数据层 中创建新节点。 可以使用 graphql 探索数据层。

运行 gatsby develop 后在 http://localhost:8000/___graphql 本地访问(参见 gatsby tutorial )

关于 Gatsby : How to query result of transformer plugin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46370498/

相关文章:

GatsbyJS - 解析带或不带 ".html"后缀的页面 URL

undefined - 类型错误 : Cannot read property 'allMarkdownRemark' of undefined - on Gatsby

javascript - 未处理的拒绝(错误): Expected undefined to be a GraphQL schema

javascript - storageRef.child 不是 firebase 中的函数

node.js - Gatsby 中的缓存破坏 page-data.json 文件

javascript - 如何以及在哪里访问 gatsby 中的 html 正文

reactjs - 使用 renderRichText - 接收错误节点未定义

asp.net-core - 在 Google 身份验证后面提供静态文件

reactjs - 每次发帖都要手动重启Gatsbyjs吗?

reactjs - Gatsby 中的服务 worker (react.js)