-
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 another node as a field
on a node
#6041
Comments
Quick update: it is possible to set another node as a Unfortunately the |
in exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
if (node.internal.type === `MarkdownRemark`) {
createNodeField({
node,
name: `heroImage`,
value: `./hero-something.jpg`, // adjust as needed here - this need to be relative path to image from your markdown file
});
}
}; this will create |
Ok wow, just to double check: Gatsby will always try to convert a field value to a file node (if the string is a valid path?). I tried to do it "manually" with
|
if field is string (or array of string) and it looks like a path, Gatsby will try to find matching --edit:
I think this might be order of creation of nodes issue here - we call |
Is that documented somewhere? I guess this does not allow for regex or wildcard matching...
That was my guess too. Is there a way to get around this: another API like ps, Thanks a lot for the help. My initial issue was resolved. Closed the issue. |
Sorry for bothering anyone on here with this question. I am currently having an issue calling onCreateNode twice. Does anyone know how to do so? for example i have if(node.internal.owner === 'gatsby-source-drupal) But i need to call it again so that i can create a new field on my menu, but it throws an error. |
@tejedamiguel6 Not sure what you try to achieve, could you elaborate a little bit more what your goal is? Edit: Or have you already solved it? |
Is it possible to add a different node as a field on a node? In my case I have
MarkdownRemark
nodes, that I want to extend with achildImageSharp
node underfields
.Some background:
The markdown node constitutes a blog post and it each blog post has a "hero" image. This is identified as a file named "hero(...)" in the same dir as the markdown post. I can currently get the hero image in the blog-post template, by passing a "regex" string in the context. Something like
"/my-blogpost\/hero/"
.It seems more powerful to simply add the
ImageSharp
node directly to thefield
, so I can directly access it anywhere I need it. Does graphql / gatsby allow for that?Sorry for adding a question here, that I can probably solve with some work, but it would really save me some time. I promise the update this post with a code sample, once I get it to work.
The text was updated successfully, but these errors were encountered: