Skip to content

Commit

Permalink
fix(gatsby-source-filesystem): Let plugins set parent when creating F…
Browse files Browse the repository at this point in the history
…ile nodes with createRemoteFileNode (#11795)

* WIP update

* Fixes to drupal/wordpress

* Add docs for parentNodeId
  • Loading branch information
KyleAMathews authored and sidharthachatterjee committed Feb 20, 2019
1 parent ad5132a commit 5a3c1fc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ exports.sourceNodes = async (
cache,
createNode,
createNodeId,
parentNodeId: node.id,
auth,
})
} catch (e) {
Expand Down
5 changes: 5 additions & 0 deletions packages/gatsby-source-filesystem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ createRemoteFileNode({
// The source url of the remote file
url: `https://example.com/a-file.jpg`,

// The id of the parent node (i.e. the node to which the new remote File node will be linked to.
parentNodeId,

// The redux store which is passed to all Node APIs.
store,

Expand Down Expand Up @@ -208,6 +211,7 @@ exports.downloadMediaFiles = ({
try {
fileNode = await createRemoteFileNode({
url: node.source_url,
parentNodeId: node.id,
store,
cache,
createNode,
Expand Down Expand Up @@ -238,6 +242,7 @@ The helper tries first to retrieve the file name and extension by parsing the ur
createRemoteFileNode({
// The source url of the remote file
url: `https://example.com/a-file-without-an-extension`,
parentNodeId: node.id,
store,
cache,
createNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ async function processRemoteNode({
store,
cache,
createNode,
parentNodeId,
auth = {},
createNodeId,
ext,
Expand Down Expand Up @@ -248,6 +249,7 @@ async function processRemoteNode({
// Create the file node.
const fileNode = await createFileNode(filename, createNodeId, {})
fileNode.internal.description = `File "${url}"`
fileNode.parent = parentNodeId
// Override the default plugin as gatsby-source-filesystem needs to
// be the owner of File nodes or there'll be conflicts if any other
// File nodes are created through normal usages of
Expand Down Expand Up @@ -305,6 +307,7 @@ module.exports = ({
store,
cache,
createNode,
parentNodeId = null,
auth = {},
createNodeId,
ext = null,
Expand Down Expand Up @@ -348,6 +351,7 @@ module.exports = ({
store,
cache,
createNode,
parentNodeId,
createNodeId,
auth,
ext,
Expand Down
6 changes: 4 additions & 2 deletions packages/gatsby-source-shopify/src/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { createNodeFactory, generateNodeId } = createNodeHelpers({
})

const downloadImageAndCreateFileNode = async (
{ url },
{ url, nodeId },
{ createNode, createNodeId, touchNode, store, cache }
) => {
let fileNodeID
Expand All @@ -41,6 +41,7 @@ const downloadImageAndCreateFileNode = async (
cache,
createNode,
createNodeId,
parentNodeId: nodeId,
})

if (fileNode) {
Expand All @@ -63,7 +64,7 @@ export const ArticleNode = imageArgs =>

if (node.image)
node.image.localFile___NODE = await downloadImageAndCreateFileNode(
{ id: node.image.id, url: node.image.src },
{ id: node.image.id, url: node.image.src, nodeId: node.id },
imageArgs
)

Expand All @@ -84,6 +85,7 @@ export const CollectionNode = imageArgs =>
{
id: node.image.id,
url: node.image.src && node.image.src.split(`?`)[0],
nodeId: node.id,
},
imageArgs
)
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-source-wordpress/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ exports.downloadMediaFiles = async ({
cache,
createNode,
createNodeId,
parentNodeId: e.id,
auth: _auth,
})

Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby-transformer-screenshot/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ exports.onPreBootstrap = (
cache,
createNode,
createNodeId,
parentNodeId: n.id,
createContentDigest,
})
} else {
Expand Down Expand Up @@ -90,6 +91,7 @@ exports.onCreateNode = async (
createNode,
createNodeId,
createContentDigest,
parentNodeId: node.id,
})
.on(`finish`, r => {
resolve(r)
Expand All @@ -115,6 +117,7 @@ const createScreenshotNode = async ({
cache,
createNode,
createNodeId,
parentNodeId,
createContentDigest,
}) => {
try {
Expand All @@ -135,6 +138,7 @@ const createScreenshotNode = async ({
cache,
createNode,
createNodeId,
parentNodeId,
})
expires = screenshotResponse.data.expires

Expand Down

0 comments on commit 5a3c1fc

Please sign in to comment.