Skip to content

Commit

Permalink
fix(gatsby-source-drupal): check relationships type exists on node be…
Browse files Browse the repository at this point in the history
…fore filtering (#33181)

* fix(gatsby-source-drupal): check relationships type exists on node before filtering

* Update packages/gatsby-source-drupal/src/utils.js

Co-authored-by: Dustin Schau <DSchau@users.noreply.github.com>

* format

Co-authored-by: Dustin Schau <DSchau@users.noreply.github.com>
  • Loading branch information
KyleAMathews and DSchau authored Sep 14, 2021
1 parent 7c726dd commit d4f8355
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/gatsby-source-drupal/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const {
nodeFromData,
downloadFile,
isFileNode,
getHref,
createNodeIdWithVersion,
} = require(`./normalize`)

Expand Down Expand Up @@ -262,10 +261,15 @@ ${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 &&
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
Expand Down

0 comments on commit d4f8355

Please sign in to comment.