diff --git a/packages/gatsby-source-drupal/src/utils.js b/packages/gatsby-source-drupal/src/utils.js index eda40f3437987..92c670367f3ef 100644 --- a/packages/gatsby-source-drupal/src/utils.js +++ b/packages/gatsby-source-drupal/src/utils.js @@ -242,7 +242,7 @@ ${JSON.stringify(nodeToUpdate, null, 4)} ` ) - const { createNode } = actions + const { createNode, unstable_createNodeManifest } = actions const newNode = nodeFromData( nodeToUpdate, @@ -250,6 +250,12 @@ ${JSON.stringify(nodeToUpdate, null, 4)} pluginOptions.entityReferenceRevisions ) + drupalCreateNodeManifest({ + attributes: nodeToUpdate.attributes, + gatsbyNode: newNode, + unstable_createNodeManifest, + }) + const nodesToUpdate = [newNode] const oldNodeReferencedNodes = referencedNodesLookup.get(newNode.id) @@ -337,5 +343,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