-
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
fix(gatsby-source-filesystem): Let plugins set parent when creating File nodes with createRemoteFileNode #11795
Conversation
Validated this code change with this gatsby-node.js: const { createRemoteFileNode } = require(`gatsby-source-filesystem`);
exports.sourceNodes = ({ actions, createNodeId }) => {
const { createNode } = actions;
createNode({
id: createNodeId(`test`),
cool: `yeah`,
url: `https://t3.ftcdn.net/jpg/00/92/53/56/240_F_92535664_IvFsQeHjBzfE6sD4VHdO8u5OHUSc6yHF.jpg`,
internal: {
type: `TESTING`,
contentDigest: `1`,
},
});
};
exports.onCreateNode = async ({
node,
actions,
store,
cache,
createNodeId,
}) => {
const { createNode, createNodeField } = actions;
if (node.internal.type === `TESTING`) {
console.log({ node, actions, createNodeId });
const fileNode = await createRemoteFileNode({
url: node.url,
store,
cache,
createNode,
createNodeId,
parentNodeId: node.id,
});
console.log({ fileNode });
createNodeField({
node,
name: `urlFile___NODE`,
value: fileNode.id,
});
}
}; |
@gatsbyjs/core bump |
I think this is good - we need to document that people need to use Should we also add warning for nodes creaated in |
Is there value in adding the above code that you validated against as an end to end test? |
Probably not — this is just normal node stuff which is tested elsewhere — the problem was just that we didn't let plugins set themselves as the parent when using @pieh yeah, will document & add warning. |
@KyleAMathews Alright, testing and verifying this locally |
Hmm actually their is no way to warn since there's no way to know which plugin called |
So there is this trick I've used for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks Kyle!
Successfully published:
|
Ooo that's cool — I'll create an issue for it. |
…ile nodes with createRemoteFileNode (gatsbyjs#11795) * WIP update * Fixes to drupal/wordpress * Add docs for parentNodeId
Not doing this is causing problems as a) when the server is restarted, if the parent of a remote File node is loaded from the cache, the linked File node won't be recreated which means it will be garbage collected and b) if a parent node is deleted, the linked File node won't also be deleted.
This PR is experimental still. Will be putting together a quick test case to make sure this fixes things.