From d2056927272d33b47d86347e61a3d21635658905 Mon Sep 17 00:00:00 2001 From: psharma-ii <82900964+psharma-ii@users.noreply.github.com> Date: Mon, 20 Sep 2021 17:23:11 -0400 Subject: [PATCH 1/4] (fix) add steps for refetch_ALL `REFETCH_ALL` action_type implemented on WPGatsby was not being handled. This takes care of that by adding a conditional for `REFETCH_ALL`, sources the Node and checks if the sourceNode has `refetchAll` boolean set in addition to other Or conditionals. To add `refetchAll` GatsbyTypes was modified to add the new property. --- .../gatsby-source-wordpress/src/steps/source-nodes/index.ts | 3 ++- .../src/steps/source-nodes/update-nodes/wp-actions/index.js | 4 ++++ packages/gatsby-source-wordpress/src/utils/gatsby-types.ts | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-source-wordpress/src/steps/source-nodes/index.ts b/packages/gatsby-source-wordpress/src/steps/source-nodes/index.ts index 9c2b85e21af23..2b33cd033fa44 100644 --- a/packages/gatsby-source-wordpress/src/steps/source-nodes/index.ts +++ b/packages/gatsby-source-wordpress/src/steps/source-nodes/index.ts @@ -10,7 +10,7 @@ import { allowFileDownloaderProgressBarToClear } from "./create-nodes/create-rem import { sourcePreviews } from "~/steps/preview" const sourceNodes: Step = async helpers => { - const { cache, webhookBody } = helpers + const { cache, webhookBody, refetchAll } = helpers // if this is a preview we want to process it and return early if (webhookBody.preview) { @@ -41,6 +41,7 @@ const sourceNodes: Step = async helpers => { const fetchEverything = foundUsableHardCachedData || !lastCompletedSourceTime || + refetchAll || // don't refetch everything in development (process.env.NODE_ENV !== `development` && // and the schema was changed diff --git a/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js b/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js index a62228baa0a58..060bd4932ec5e 100644 --- a/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js +++ b/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js @@ -6,6 +6,7 @@ import { paginatedWpNodeFetch } from "~/steps/source-nodes/fetch-nodes/fetch-nod import fetchAndCreateNonNodeRootFields from "~/steps/source-nodes/create-nodes/fetch-and-create-non-node-root-fields" import { setHardCachedNodes } from "~/utils/cache" +import { sourceNodes } from "~/steps/source-nodes" /** * getWpActions @@ -60,6 +61,9 @@ export const handleWpActions = async api => { break case `NON_NODE_ROOT_FIELDS`: await fetchAndCreateNonNodeRootFields() + case `REFETCH_ALL`: + helpers.refetchAll = true; + await sourceNodes(helpers, {}) } await setHardCachedNodes({ helpers }) diff --git a/packages/gatsby-source-wordpress/src/utils/gatsby-types.ts b/packages/gatsby-source-wordpress/src/utils/gatsby-types.ts index dc753ec42c843..66d757f2d6fcf 100644 --- a/packages/gatsby-source-wordpress/src/utils/gatsby-types.ts +++ b/packages/gatsby-source-wordpress/src/utils/gatsby-types.ts @@ -9,6 +9,7 @@ export type GatsbyNodeApiHelpers = NodePluginArgs & { context: any updatedAt: number } + refetchAll?: boolean } export type GatsbyHelpers = GatsbyNodeApiHelpers export type GatsbyReporter = Reporter From bb432bab34c45b7ccf6a69f10eb3ec83b01d0e26 Mon Sep 17 00:00:00 2001 From: psharma-ii <82900964+psharma-ii@users.noreply.github.com> Date: Tue, 12 Oct 2021 19:31:55 -0400 Subject: [PATCH 2/4] Update index.js --- .../src/steps/source-nodes/update-nodes/wp-actions/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js b/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js index 060bd4932ec5e..62b9da85dbdac 100644 --- a/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js +++ b/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js @@ -62,8 +62,7 @@ export const handleWpActions = async api => { case `NON_NODE_ROOT_FIELDS`: await fetchAndCreateNonNodeRootFields() case `REFETCH_ALL`: - helpers.refetchAll = true; - await sourceNodes(helpers, {}) + await sourceNodes({ ...helpers, refetchAll: true }, {}) } await setHardCachedNodes({ helpers }) From ea6c3c01e1280b192c07b96814e2b3bf09e075d2 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Mon, 18 Oct 2021 14:35:40 -0700 Subject: [PATCH 3/4] formatting --- .../src/steps/source-nodes/update-nodes/wp-actions/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js b/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js index 62b9da85dbdac..73cf9414023e8 100644 --- a/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js +++ b/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js @@ -62,7 +62,7 @@ export const handleWpActions = async api => { case `NON_NODE_ROOT_FIELDS`: await fetchAndCreateNonNodeRootFields() case `REFETCH_ALL`: - await sourceNodes({ ...helpers, refetchAll: true }, {}) + await sourceNodes({ ...helpers, refetchAll: true }, {}) } await setHardCachedNodes({ helpers }) From cff082d4272288314bc5c2b0002152d39d825475 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Mon, 18 Oct 2021 15:11:45 -0700 Subject: [PATCH 4/4] add break --- .../src/steps/source-nodes/update-nodes/wp-actions/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js b/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js index 73cf9414023e8..c0d1ac2d5204a 100644 --- a/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js +++ b/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/index.js @@ -61,6 +61,7 @@ export const handleWpActions = async api => { break case `NON_NODE_ROOT_FIELDS`: await fetchAndCreateNonNodeRootFields() + break case `REFETCH_ALL`: await sourceNodes({ ...helpers, refetchAll: true }, {}) }