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

feat(gatsby-source-drupal): Add node manifest support for previews #33683

Merged
merged 9 commits into from
Nov 5, 2021
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 @@ -242,14 +242,20 @@ ${JSON.stringify(nodeToUpdate, null, 4)}
`
)

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

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

drupalCreateNodeManifest({
pvorozhe marked this conversation as resolved.
Show resolved Hide resolved
attributes: nodeToUpdate.attributes,
gatsbyNode: newNode,
unstable_createNodeManifest,
})

const nodesToUpdate = [newNode]

const oldNodeReferencedNodes = referencedNodesLookup.get(newNode.id)
Expand Down Expand Up @@ -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({
TylerBarnes marked this conversation as resolved.
Show resolved Hide resolved
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