From ed925aa1055400d724b68f282fbf64979868e97a Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Tue, 14 Sep 2021 10:57:11 -0700 Subject: [PATCH 1/3] fix(gatsby-source-drupal): check relationships type exists on node before filtering --- packages/gatsby-source-drupal/src/utils.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/gatsby-source-drupal/src/utils.js b/packages/gatsby-source-drupal/src/utils.js index ed19cbca059b1..c4afc4ef4a6a5 100644 --- a/packages/gatsby-source-drupal/src/utils.js +++ b/packages/gatsby-source-drupal/src/utils.js @@ -4,7 +4,6 @@ const { nodeFromData, downloadFile, isFileNode, - getHref, createNodeIdWithVersion, } = require(`./normalize`) @@ -262,10 +261,12 @@ ${JSON.stringify(nodeToUpdate, null, 4)} const nodeFieldName = `${newNode.internal.type}___NODE` removedReferencedNodes.forEach(referencedNode => { - referencedNode.relationships[nodeFieldName] = - referencedNode.relationships[nodeFieldName].filter( - id => id !== newNode.id - ) + if (referencedNode.relationships[nodeFieldName]) { + referencedNode.relationships[nodeFieldName] = + referencedNode.relationships[nodeFieldName].filter( + id => id !== newNode.id + ) + } }) // see what nodes are newly referenced, and make sure to call `createNode` on them From 6e5d0ddc6a153bccc0590cbcf8a6ae231e05aa38 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Tue, 14 Sep 2021 15:23:12 -0700 Subject: [PATCH 2/3] Update packages/gatsby-source-drupal/src/utils.js Co-authored-by: Dustin Schau --- packages/gatsby-source-drupal/src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-drupal/src/utils.js b/packages/gatsby-source-drupal/src/utils.js index c4afc4ef4a6a5..3683a424d254a 100644 --- a/packages/gatsby-source-drupal/src/utils.js +++ b/packages/gatsby-source-drupal/src/utils.js @@ -261,7 +261,7 @@ ${JSON.stringify(nodeToUpdate, null, 4)} const nodeFieldName = `${newNode.internal.type}___NODE` removedReferencedNodes.forEach(referencedNode => { - if (referencedNode.relationships[nodeFieldName]) { + if (referencedNode.relationships && referencedNode.relationships[nodeFieldName]) { referencedNode.relationships[nodeFieldName] = referencedNode.relationships[nodeFieldName].filter( id => id !== newNode.id From 53ee03e2a1bd7565239ab60ddb261b1db0adcee9 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Tue, 14 Sep 2021 15:31:03 -0700 Subject: [PATCH 3/3] format --- packages/gatsby-source-drupal/src/utils.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-source-drupal/src/utils.js b/packages/gatsby-source-drupal/src/utils.js index 3683a424d254a..1103a2ccff49e 100644 --- a/packages/gatsby-source-drupal/src/utils.js +++ b/packages/gatsby-source-drupal/src/utils.js @@ -261,7 +261,10 @@ ${JSON.stringify(nodeToUpdate, null, 4)} const nodeFieldName = `${newNode.internal.type}___NODE` removedReferencedNodes.forEach(referencedNode => { - if (referencedNode.relationships && referencedNode.relationships[nodeFieldName]) { + if ( + referencedNode.relationships && + referencedNode.relationships[nodeFieldName] + ) { referencedNode.relationships[nodeFieldName] = referencedNode.relationships[nodeFieldName].filter( id => id !== newNode.id