Skip to content

Commit

Permalink
fix(gatsby-source-wordpress): draft previews (#32915)
Browse files Browse the repository at this point in the history
* debug

* fix draft previews

* invoke leftover callbacks at the start of preview sourcing

* use proper status
  • Loading branch information
TylerBarnes authored and wardpeet committed Aug 27, 2021
1 parent 26dc226 commit 152050f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
14 changes: 6 additions & 8 deletions packages/gatsby-source-wordpress/src/steps/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { formatLogMessage } from "~/utils/format-log-message"
import { touchValidNodes } from "../source-nodes/update-nodes/fetch-node-updates"

import { Reporter } from "gatsby/reporter"
import { invokeAndCleanupLeftoverPreviewCallbacks } from "./cleanup"

const inDevelopPreview =
process.env.NODE_ENV === `development` &&
Expand Down Expand Up @@ -367,14 +368,11 @@ export const sourcePreviews = async (helpers: GatsbyHelpers): Promise<void> => {
dump(webhookBody)
}

if (previewForIdIsAlreadyBeingProcessed(webhookBody?.id)) {
if (inPreviewDebugMode) {
reporter.info(
`Preview for id ${webhookBody?.id} is already being sourced.`
)
}
return
}
// in case there are preview callbacks from our last build
await invokeAndCleanupLeftoverPreviewCallbacks({
status: `GATSBY_PREVIEW_PROCESS_ERROR`,
context: `Starting sourcePreviews`,
})

const wpGatsbyPreviewNodeManifestsAreSupported =
await remoteSchemaSupportsFieldNameOnTypeName({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const fetchAndCreateSingleNode = async ({
cachedNodeIds,
token = null,
isPreview = false,
isDraft = false,
userDatabaseId = null,
}) => {
function getNodeQuery() {
Expand All @@ -34,7 +35,7 @@ export const fetchAndCreateSingleNode = async ({
// if it's a preview but it's the initial blank node
// then use the regular node query as the preview query wont
// return anything
const query = isPreview ? previewQuery : nodeQuery
const query = isPreview && !isDraft ? previewQuery : nodeQuery

return query
}
Expand Down Expand Up @@ -81,6 +82,16 @@ export const fetchAndCreateSingleNode = async ({
)
)

reporter.info({
singleName,
id,
actionType,
cachedNodeIds,
token,
isPreview,
userDatabaseId,
})

return { node: null }
}

Expand Down

0 comments on commit 152050f

Please sign in to comment.