From da21c7f0ba170e2e8868251b7d584795e823b38d Mon Sep 17 00:00:00 2001 From: Polina Vorozheykina Date: Tue, 26 Oct 2021 12:25:04 -0700 Subject: [PATCH 1/8] Drupal plugin: Add node manofest support. --- .../gatsby-source-drupal/src/gatsby-node.js | 1 + packages/gatsby-source-drupal/src/utils.js | 36 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-source-drupal/src/gatsby-node.js b/packages/gatsby-source-drupal/src/gatsby-node.js index 7ca4bdb25a0ac..755bb1c2bc5a0 100644 --- a/packages/gatsby-source-drupal/src/gatsby-node.js +++ b/packages/gatsby-source-drupal/src/gatsby-node.js @@ -686,6 +686,7 @@ exports.onCreateDevServer = ( getNode, reporter, store, + unstable_createNodeManifest, }, pluginOptions ) diff --git a/packages/gatsby-source-drupal/src/utils.js b/packages/gatsby-source-drupal/src/utils.js index eda40f3437987..f320f8044c769 100644 --- a/packages/gatsby-source-drupal/src/utils.js +++ b/packages/gatsby-source-drupal/src/utils.js @@ -1,3 +1,4 @@ +const { has } = require("lodash") const _ = require(`lodash`) const { @@ -242,7 +243,7 @@ ${JSON.stringify(nodeToUpdate, null, 4)} ` ) - const { createNode } = actions + const { createNode, unstable_createNodeManifest } = actions const newNode = nodeFromData( nodeToUpdate, @@ -250,6 +251,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 +344,32 @@ ${JSON.stringify(nodeToUpdate, null, 4)} } } +let hasLogs = 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, +}) { + if (typeof unstable_createNodeManifest === `function`) { + 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 (!hasLogs) { + hasLogs = 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 From b5d31a8ebd22cb1132785ac6d3d9823f37faec65 Mon Sep 17 00:00:00 2001 From: Polina Vorozheykina Date: Tue, 26 Oct 2021 12:25:47 -0700 Subject: [PATCH 2/8] Drupal plugin: Add node manofest support. --- packages/gatsby-source-drupal/src/gatsby-node.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/gatsby-source-drupal/src/gatsby-node.js b/packages/gatsby-source-drupal/src/gatsby-node.js index 755bb1c2bc5a0..7ca4bdb25a0ac 100644 --- a/packages/gatsby-source-drupal/src/gatsby-node.js +++ b/packages/gatsby-source-drupal/src/gatsby-node.js @@ -686,7 +686,6 @@ exports.onCreateDevServer = ( getNode, reporter, store, - unstable_createNodeManifest, }, pluginOptions ) From 5261c7e3588746001546e4cea9449b1c865ee9a0 Mon Sep 17 00:00:00 2001 From: Polina Vorozheykina Date: Tue, 26 Oct 2021 12:33:24 -0700 Subject: [PATCH 3/8] Remove extra import. --- packages/gatsby-source-drupal/src/utils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/gatsby-source-drupal/src/utils.js b/packages/gatsby-source-drupal/src/utils.js index f320f8044c769..a8a65d860a825 100644 --- a/packages/gatsby-source-drupal/src/utils.js +++ b/packages/gatsby-source-drupal/src/utils.js @@ -1,4 +1,3 @@ -const { has } = require("lodash") const _ = require(`lodash`) const { From d192da0cb242356b8b40c77e472533bd44825a4f Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Tue, 26 Oct 2021 13:01:19 -0700 Subject: [PATCH 4/8] Add node id to log --- packages/gatsby-source-drupal/src/utils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-source-drupal/src/utils.js b/packages/gatsby-source-drupal/src/utils.js index a8a65d860a825..5b874e66f76bb 100644 --- a/packages/gatsby-source-drupal/src/utils.js +++ b/packages/gatsby-source-drupal/src/utils.js @@ -356,7 +356,9 @@ function drupalCreateNodeManifest({ if (typeof unstable_createNodeManifest === `function`) { const manifestId = `${attributes.drupal_internal__nid}-${attributes.revision_timestamp}` - console.info(`Drupal: Creating node manifest with id ${manifestId}`) + console.info( + `Drupal: Creating node manifest with id ${manifestId} for node ${gatsbyNode?.id}` + ) unstable_createNodeManifest({ manifestId, From d22c5826f09b34c127ca40f32acc1a356533d3ed Mon Sep 17 00:00:00 2001 From: Polina Vorozheykina Date: Wed, 27 Oct 2021 15:02:02 -0700 Subject: [PATCH 5/8] Add checks for preview mode. --- packages/gatsby-source-drupal/package.json | 9 +++++---- packages/gatsby-source-drupal/src/utils.js | 7 ++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/gatsby-source-drupal/package.json b/packages/gatsby-source-drupal/package.json index bc692b4d75bda..f1860027a7c96 100644 --- a/packages/gatsby-source-drupal/package.json +++ b/packages/gatsby-source-drupal/package.json @@ -1,7 +1,7 @@ { "name": "gatsby-source-drupal", "description": "Gatsby source plugin for building websites using the Drupal CMS as a data source", - "version": "5.1.0-next.0", + "version": "5.1.0-alpha-drupal-content-sync.33+5261c7e358", "author": "Kyle Mathews ", "bugs": { "url": "https://github.com/gatsbyjs/gatsby/issues" @@ -13,7 +13,7 @@ "bluebird": "^3.7.2", "body-parser": "^1.19.0", "fastq": "^1.11.1", - "gatsby-source-filesystem": "^4.1.0-next.0", + "gatsby-source-filesystem": "4.1.0-next.0", "got": "^11.8.2", "http2-wrapper": "^2.0.5", "lodash": "^4.17.21", @@ -24,7 +24,7 @@ "devDependencies": { "@babel/cli": "^7.15.4", "@babel/core": "^7.15.5", - "babel-preset-gatsby-package": "^2.1.0-next.0", + "babel-preset-gatsby-package": "2.1.0-next.0", "cross-env": "^7.0.3" }, "engines": { @@ -49,5 +49,6 @@ "build": "babel src --out-dir . --ignore \"**/__tests__\"", "prepare": "cross-env NODE_ENV=production npm run build", "watch": "babel -w src --out-dir . --ignore \"**/__tests__\"" - } + }, + "gitHead": "5261c7e3588746001546e4cea9449b1c865ee9a0" } diff --git a/packages/gatsby-source-drupal/src/utils.js b/packages/gatsby-source-drupal/src/utils.js index a8a65d860a825..368a882092077 100644 --- a/packages/gatsby-source-drupal/src/utils.js +++ b/packages/gatsby-source-drupal/src/utils.js @@ -353,7 +353,12 @@ function drupalCreateNodeManifest({ gatsbyNode, unstable_createNodeManifest, }) { - if (typeof unstable_createNodeManifest === `function`) { + 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}`) From a09bbfa140a0f7c20a24403f891e12e80a47f4c0 Mon Sep 17 00:00:00 2001 From: Polina Vorozheykina Date: Wed, 27 Oct 2021 15:10:19 -0700 Subject: [PATCH 6/8] Change log message. --- packages/gatsby-source-drupal/src/utils.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/gatsby-source-drupal/src/utils.js b/packages/gatsby-source-drupal/src/utils.js index 6011b08bf8528..368a882092077 100644 --- a/packages/gatsby-source-drupal/src/utils.js +++ b/packages/gatsby-source-drupal/src/utils.js @@ -361,9 +361,7 @@ function drupalCreateNodeManifest({ if (typeof unstable_createNodeManifest === `function` && isPreview) { const manifestId = `${attributes.drupal_internal__nid}-${attributes.revision_timestamp}` - console.info( - `Drupal: Creating node manifest with id ${manifestId} for node ${gatsbyNode?.id}` - ) + console.info(`Drupal: Creating node manifest with id ${manifestId}`) unstable_createNodeManifest({ manifestId, From 5da37596bc6c5f7662efa8db9235d4348cc40096 Mon Sep 17 00:00:00 2001 From: Polina Vorozheykina Date: Wed, 27 Oct 2021 15:12:37 -0700 Subject: [PATCH 7/8] Change log message. --- packages/gatsby-source-drupal/package.json | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/gatsby-source-drupal/package.json b/packages/gatsby-source-drupal/package.json index f1860027a7c96..bc692b4d75bda 100644 --- a/packages/gatsby-source-drupal/package.json +++ b/packages/gatsby-source-drupal/package.json @@ -1,7 +1,7 @@ { "name": "gatsby-source-drupal", "description": "Gatsby source plugin for building websites using the Drupal CMS as a data source", - "version": "5.1.0-alpha-drupal-content-sync.33+5261c7e358", + "version": "5.1.0-next.0", "author": "Kyle Mathews ", "bugs": { "url": "https://github.com/gatsbyjs/gatsby/issues" @@ -13,7 +13,7 @@ "bluebird": "^3.7.2", "body-parser": "^1.19.0", "fastq": "^1.11.1", - "gatsby-source-filesystem": "4.1.0-next.0", + "gatsby-source-filesystem": "^4.1.0-next.0", "got": "^11.8.2", "http2-wrapper": "^2.0.5", "lodash": "^4.17.21", @@ -24,7 +24,7 @@ "devDependencies": { "@babel/cli": "^7.15.4", "@babel/core": "^7.15.5", - "babel-preset-gatsby-package": "2.1.0-next.0", + "babel-preset-gatsby-package": "^2.1.0-next.0", "cross-env": "^7.0.3" }, "engines": { @@ -49,6 +49,5 @@ "build": "babel src --out-dir . --ignore \"**/__tests__\"", "prepare": "cross-env NODE_ENV=production npm run build", "watch": "babel -w src --out-dir . --ignore \"**/__tests__\"" - }, - "gitHead": "5261c7e3588746001546e4cea9449b1c865ee9a0" + } } From a02237f9fa26af5fa58f4ab23eff2fd51802e3aa Mon Sep 17 00:00:00 2001 From: Polina Vorozheykina Date: Fri, 5 Nov 2021 13:22:01 -0700 Subject: [PATCH 8/8] Rename hasLogs to hasLoggedContentSyncWarning --- packages/gatsby-source-drupal/src/utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-source-drupal/src/utils.js b/packages/gatsby-source-drupal/src/utils.js index 368a882092077..92c670367f3ef 100644 --- a/packages/gatsby-source-drupal/src/utils.js +++ b/packages/gatsby-source-drupal/src/utils.js @@ -343,7 +343,7 @@ ${JSON.stringify(nodeToUpdate, null, 4)} } } -let hasLogs = false +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. @@ -367,8 +367,8 @@ function drupalCreateNodeManifest({ manifestId, node: gatsbyNode, }) - } else if (!hasLogs) { - hasLogs = true + } 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.` )