Skip to content

Commit

Permalink
feat(gatsby-source-drupal): Add node manifest support for previews (#…
Browse files Browse the repository at this point in the history
…33683)

* Drupal plugin: Add node manifest support.
  • Loading branch information
pvorozhe authored Nov 5, 2021
1 parent 09effad commit 3dc7629
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion packages/gatsby-source-drupal/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,20 @@ ${JSON.stringify(nodeToUpdate, null, 4)}
`
)

const { createNode } = actions
const { createNode, unstable_createNodeManifest } = actions

const newNode = nodeFromData(
nodeToUpdate,
createNodeId,
pluginOptions.entityReferenceRevisions
)

drupalCreateNodeManifest({
attributes: nodeToUpdate.attributes,
gatsbyNode: newNode,
unstable_createNodeManifest,
})

const nodesToUpdate = [newNode]

const oldNodeReferencedNodes = referencedNodesLookup.get(newNode.id)
Expand Down Expand Up @@ -369,5 +375,37 @@ ${JSON.stringify(nodeToUpdate, null, 4)}
}
}

let hasLoggedContentSyncWarning = false
/**
* This fn creates node manifests which are used for Gatsby Cloud Previews via the Content Sync API/feature.
* Content Sync routes a user from Drupal to a page created from the entry data they're interested in previewing.
*/
function drupalCreateNodeManifest({
attributes,
gatsbyNode,
unstable_createNodeManifest,
}) {
const isPreview =
(process.env.NODE_ENV === `development` &&
process.env.ENABLE_GATSBY_REFRESH_ENDPOINT) ||
process.env.GATSBY_IS_PREVIEW === `true`

if (typeof unstable_createNodeManifest === `function` && isPreview) {
const manifestId = `${attributes.drupal_internal__nid}-${attributes.revision_timestamp}`

console.info(`Drupal: Creating node manifest with id ${manifestId}`)

unstable_createNodeManifest({
manifestId,
node: gatsbyNode,
})
} else if (!hasLoggedContentSyncWarning) {
hasLoggedContentSyncWarning = true
console.warn(
`Drupal: Your version of Gatsby core doesn't support Content Sync (via the unstable_createNodeManifest action). Please upgrade to the latest version to use Content Sync in your site.`
)
}
}

exports.handleWebhookUpdate = handleWebhookUpdate
exports.handleDeletedNode = handleDeletedNode

0 comments on commit 3dc7629

Please sign in to comment.