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) #34017

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Changes from all commits
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
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