I am using onCreateNode and createNodeField as I have seen referenced in many places, but node fields are not being added.
Gatsby version: 1.9.54
Node.js version: 8.8.1
Operating System: MacOS High Sierra
In my gatsby-node.js:
exports.onCreateNode = ({
node, boundActionCreators,
}) => {
const { createNodeField } = boundActionCreators
createNodeField({
node,
name: 'shareLink',
value: 'arbitrary string'
})
}
I have tried limiting the code to check for specific node.internal.type, as well as removed the .cache folder as referenced in other issues.
"shareLink" field is not added. It is not discoverable in the graphql debugger and throws errors when the site attempts to access the field.
"shareLink" field should exist in page nodes.
Surely I must be doing something wrong, but that would baffle me, given how many examples I have referenced for this functionality.
Did you look under fields? The new field should be at node.fields.newField.
Arg. That's the issue. Apologies, I didn't find that referenced!
Curious where you were looking? Would love a PR from you to clarify that part of the docs!
I'm having this exact issue and I have looked under node.fields which does not seem to exist.
I can only see the field added if I console out that node inside of onCreateNode just after calling actions.createNodeField
exports.onCreateNode = ({ node, actions, getNode }) => {
if (!isLeverNode(node)) return;
actions.createNodeField({
node,
name: 'slug',
value: `${node.lever_id}_test`,
});
};
I am having the same issue as @iDVB
I'm experiencing this same issue that @iDVB and @liltechnomancer is describing. Meaning, it shows up as node.fields.<name_of_field> inside of the onCreateNode function but not in a subsequent GQL query. If it's of any use, I'm trying to extend a node of the type Mdx.
Any insights?
Same here, using gatsby-source-prismic plugin
If I remember correctly, my issue was that I was running some async calls which I never made the gatsby API aware of(like a missing await or something like that). This is vague in my memory so take it with a grain of salt, but I recall my error being flaky and not consistent. https://www.gatsbyjs.org/docs/debugging-async-lifecycles/ was helpful anyways.
If I remember correctly, my issue was that I was running some async calls which I never made the gatsby API aware of(like a missing
awaitor something like that). This is vague in my memory so take it with a grain of salt, but I recall my error being flaky and not consistent. https://www.gatsbyjs.org/docs/debugging-async-lifecycles/ was helpful anyways.
Sadly, this does not seem to be the issue, or it is beyond my understanding of the inner workings of Gatsby and I have no clue how to deal with that anyway. .
When I call createNodeField without any conditions, it appeares on gatsby nodes, that are not set up with the plugin. The plugin itself keeps on ignoring any attempt to add anything.
exports.onCreateNode = ({ node, actions}) => {
const { createNodeField } = actions;
// this adds x at some nodes, like allSitePage
createNodeField({
node,
name:x,
value:x,
});
// this is nowhere to be found..
if (node.internal.type ===PrismicBlogpost) {
createNodeField({
node,
name:slug,
value:/blog/${node.uid},
});
console.log(actions, node)
}
};
but this seems to be more of gatsby-source-prismic issue, so I it does not belong in here
Most helpful comment
Curious where you were looking? Would love a PR from you to clarify that part of the docs!