Skip to content
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-drupal): Ensure all new nodes are created before creating relationships #33864

Merged
merged 3 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add support for webhook bodies as well
  • Loading branch information
KyleAMathews committed Nov 5, 2021
commit 9f0b6691c4d9c5b57193900ea7371d9c1193373f
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"action": "update",
"data": [
{
"type": "node--article",
"id": "article-10",
"attributes": {
"id": 100,
"uuid": "article-10",
"title": "Article #10",
"body": "Aliquam non varius libero, sit amet consequat ex. Aenean porta turpis quis vulputate blandit. Suspendisse in porta erat. Sed sit amet scelerisque turpis, at rutrum mauris. Sed tempor eleifend lobortis. Proin maximus, massa sed dignissim sollicitudin, quam risus mattis justo, sit amet aliquam odio ligula quis urna. Interdum et malesuada fames ac ante ipsum primis in faucibus. Ut mollis leo nisi, at interdum urna fermentum ut. Fusce id suscipit neque, eu fermentum lacus. Donec egestas laoreet felis ac luctus. Vestibulum molestie mattis ante, a vulputate nunc ullamcorper at. Ut hendrerit ipsum eget gravida ultricies."
},
"relationships": {
"field_tags": {
"data": [
{
"type": "taxonomy_term--tags",
"id": "tag-10"
}
]
}
}
},
{
"type": "taxonomy_term--tags",
"id": "tag-10",
"attributes": {
"id": 110,
"uuid": "tag-10",
"langcode": "en",
"name": "Tag #10",
"description": null,
"weight": 0,
"changed": 1523031646,
"default_langcode": true,
"path": {
"alias": null,
"pid": null,
"langcode": "en"
}
}
}
]
}

20 changes: 20 additions & 0 deletions packages/gatsby-source-drupal/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,26 @@ describe(`gatsby-source-drupal`, () => {
})
})
})
describe(`multiple entities in webhook body`, () => {
let resp
beforeAll(async () => {
const webhookBody = require(`./fixtures/webhook-body-multiple-nodes.json`)
await sourceNodes(
{
...args,
webhookBody,
},
{ baseUrl }
)
})

it(`Relationships`, async () => {
expect(
nodes[createNodeId(`und.article-10`)].relationships.field_tags___NODE
.length
).toBe(1)
})
})

describe(`Insert content`, () => {
it(`Node doesn't exist before webhook`, () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,17 @@ ${JSON.stringify(webhookBody, null, 4)}`
nodesToUpdate = [data]
}

for (const nodeToUpdate of nodesToUpdate) {
await createNodeIfItDoesNotExist({
nodeToUpdate,
actions,
createNodeId,
createContentDigest,
getNode,
reporter,
})
}

for (const nodeToUpdate of nodesToUpdate) {
await handleWebhookUpdate(
{
Expand Down