For learning purposes I wrote a Gatsby transformer that reverses node content. I use it with gatsby-source-filesystem, only operating on .test files:
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);
}
Unfortunately, I am still very new to Gatsby, so I am struggling to find out if this is working. Taking a look at the official transformers, they not only implement gatsby-node.js (thats what I have), but also extend-node-type.js, but I couldn't find any documentation on this.
How can I query the result of my transformer?