From a1439c8801f6b4cee4346e47c9f319071945f40f Mon Sep 17 00:00:00 2001 From: psharma-ii <82900964+psharma-ii@users.noreply.github.com> Date: Tue, 19 Oct 2021 15:19:38 -0400 Subject: [PATCH] fix(gatsby-source-wordpress): Add steps for `refetch_ALL` (#33264) Co-authored-by: Tyler Barnes --- .../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..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 @@ -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() + break + case `REFETCH_ALL`: + await sourceNodes({ ...helpers, refetchAll: true }, {}) } 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