-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a node field #1471
Comments
Have you tried running the query in graphiql? |
Can you verify your |
It's getting called & returning an object with type |
Oh there is is. Your code has an if statement filtering nodes to only those of type "File". If you try querying File you'll see your field. You need to add the slug to nodes of type MarkdownRemark. Check out my blog for this pattern github.com/kyleamathews/blog |
Thanks @KyleAMathews |
I had the same problem doing the tutorial the programmatically create page. @KyleAMathews can you explain what was your solution. I don't understand the pattern github.com/kyleamathews/blog. |
@morattoo You need something like this for example in Kyle's blog he is adding this field on exports.onCreateNode = ({node, actions}) => {
const {createNodeField} = actions
switch (node.internal.type) {
case '<FIELD TYPE YOU WANT TO CHANGE>': { // <-- Change this to match your usage.
const {
fileAbsolutePath,
} = node
createNodeField({
node,
name: 'slug',
value: `/blog/${path.basename(fileAbsolutePath, '.md')}`,
})
}
}
} |
Also having no luck getting a custom field to stick to a node. exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions;
if (!isLeverNode(node)) return;
createNodeField({
node,
name: 'slug',
value: `${node.lever_id}_dvb`,
});
console.log('onCreateNode', node);
}; That console.log shows the |
What ended up happening with this? Shouldn't the solution ultimately be to fix the code samples here: https://www.gatsbyjs.com/tutorial/part-seven/ ? Is there really that few people walking through the tutorial? |
Root cause for me was I had put gatsby-node.js in the src folder instead of the root of the site as the tutorial directs -- my bad. Hopefully this helps someone else. |
I'm trying to add a
slug
node field, had a look athttps://github.com/gatsbyjs/gatsby/blob/master/www/gatsby-node.js
&https://github.com/gatsbyjs/gatsby/blob/master/www/src/templates/template-blog-post.js
And here is my
onCreateNode
functionand the query
But when I try to run this I get
GraphQLError: Cannot query field "fields" on type "MarkdownRemark"
any idea what am I doing wrong here?The text was updated successfully, but these errors were encountered: