Skip to content

Commit 5a3c1fc

Browse files
KyleAMathewssidharthachatterjee
authored andcommitted
fix(gatsby-source-filesystem): Let plugins set parent when creating File nodes with createRemoteFileNode (#11795)
* WIP update * Fixes to drupal/wordpress * Add docs for parentNodeId
1 parent ad5132a commit 5a3c1fc

File tree

6 files changed

+19
-2
lines changed

6 files changed

+19
-2
lines changed

packages/gatsby-source-drupal/src/gatsby-node.js

+1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ exports.sourceNodes = async (
208208
cache,
209209
createNode,
210210
createNodeId,
211+
parentNodeId: node.id,
211212
auth,
212213
})
213214
} catch (e) {

packages/gatsby-source-filesystem/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ createRemoteFileNode({
163163
// The source url of the remote file
164164
url: `https://example.com/a-file.jpg`,
165165

166+
// The id of the parent node (i.e. the node to which the new remote File node will be linked to.
167+
parentNodeId,
168+
166169
// The redux store which is passed to all Node APIs.
167170
store,
168171

@@ -208,6 +211,7 @@ exports.downloadMediaFiles = ({
208211
try {
209212
fileNode = await createRemoteFileNode({
210213
url: node.source_url,
214+
parentNodeId: node.id,
211215
store,
212216
cache,
213217
createNode,
@@ -238,6 +242,7 @@ The helper tries first to retrieve the file name and extension by parsing the ur
238242
createRemoteFileNode({
239243
// The source url of the remote file
240244
url: `https://example.com/a-file-without-an-extension`,
245+
parentNodeId: node.id,
241246
store,
242247
cache,
243248
createNode,

packages/gatsby-source-filesystem/src/create-remote-file-node.js

+4
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ async function processRemoteNode({
183183
store,
184184
cache,
185185
createNode,
186+
parentNodeId,
186187
auth = {},
187188
createNodeId,
188189
ext,
@@ -248,6 +249,7 @@ async function processRemoteNode({
248249
// Create the file node.
249250
const fileNode = await createFileNode(filename, createNodeId, {})
250251
fileNode.internal.description = `File "${url}"`
252+
fileNode.parent = parentNodeId
251253
// Override the default plugin as gatsby-source-filesystem needs to
252254
// be the owner of File nodes or there'll be conflicts if any other
253255
// File nodes are created through normal usages of
@@ -305,6 +307,7 @@ module.exports = ({
305307
store,
306308
cache,
307309
createNode,
310+
parentNodeId = null,
308311
auth = {},
309312
createNodeId,
310313
ext = null,
@@ -348,6 +351,7 @@ module.exports = ({
348351
store,
349352
cache,
350353
createNode,
354+
parentNodeId,
351355
createNodeId,
352356
auth,
353357
ext,

packages/gatsby-source-shopify/src/nodes.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const { createNodeFactory, generateNodeId } = createNodeHelpers({
2121
})
2222

2323
const downloadImageAndCreateFileNode = async (
24-
{ url },
24+
{ url, nodeId },
2525
{ createNode, createNodeId, touchNode, store, cache }
2626
) => {
2727
let fileNodeID
@@ -41,6 +41,7 @@ const downloadImageAndCreateFileNode = async (
4141
cache,
4242
createNode,
4343
createNodeId,
44+
parentNodeId: nodeId,
4445
})
4546

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

6465
if (node.image)
6566
node.image.localFile___NODE = await downloadImageAndCreateFileNode(
66-
{ id: node.image.id, url: node.image.src },
67+
{ id: node.image.id, url: node.image.src, nodeId: node.id },
6768
imageArgs
6869
)
6970

@@ -84,6 +85,7 @@ export const CollectionNode = imageArgs =>
8485
{
8586
id: node.image.id,
8687
url: node.image.src && node.image.src.split(`?`)[0],
88+
nodeId: node.id,
8789
},
8890
imageArgs
8991
)

packages/gatsby-source-wordpress/src/normalize.js

+1
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ exports.downloadMediaFiles = async ({
500500
cache,
501501
createNode,
502502
createNodeId,
503+
parentNodeId: e.id,
503504
auth: _auth,
504505
})
505506

packages/gatsby-transformer-screenshot/src/gatsby-node.js

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ exports.onPreBootstrap = (
4444
cache,
4545
createNode,
4646
createNodeId,
47+
parentNodeId: n.id,
4748
createContentDigest,
4849
})
4950
} else {
@@ -90,6 +91,7 @@ exports.onCreateNode = async (
9091
createNode,
9192
createNodeId,
9293
createContentDigest,
94+
parentNodeId: node.id,
9395
})
9496
.on(`finish`, r => {
9597
resolve(r)
@@ -115,6 +117,7 @@ const createScreenshotNode = async ({
115117
cache,
116118
createNode,
117119
createNodeId,
120+
parentNodeId,
118121
createContentDigest,
119122
}) => {
120123
try {
@@ -135,6 +138,7 @@ const createScreenshotNode = async ({
135138
cache,
136139
createNode,
137140
createNodeId,
141+
parentNodeId,
138142
})
139143
expires = screenshotResponse.data.expires
140144

0 commit comments

Comments
 (0)