Skip to content

Commit

Permalink
Fix: Contentful warm builds (#34678)
Browse files Browse the repository at this point in the history
Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
  • Loading branch information
axe312ger and gatsbybot authored Feb 4, 2022
1 parent bbe6554 commit d43112f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@ jobs:
- e2e-test:
test_path: e2e-tests/contentful
test_command: yarn test
# we build a second time to see if warm/cached builds are successful
- e2e-test:
test_path: e2e-tests/contentful
test_command: yarn build
- store_artifacts:
path: e2e-tests/contentful/__diff_output__
- store_test_results:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ describe(`gatsby-node`, () => {
setPluginStatus: jest.fn(),
createNode: jest.fn(async node => {
node.internal.owner = `gatsby-source-contentful`
// don't allow mutations (this isn't traversing so only top level is frozen)
currentNodeMap.set(node.id, Object.freeze(node))
currentNodeMap.set(node.id, node)
}),
deleteNode: jest.fn(node => {
currentNodeMap.delete(node.id)
Expand Down
30 changes: 16 additions & 14 deletions packages/gatsby-source-contentful/src/source-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ export async function sourceNodes(
actions
const online = await isOnline()

getNodes().forEach(node => {
if (node.internal.owner !== `gatsby-source-contentful`) {
return
}
touchNode(node)
if (node?.fields?.localFile) {
// Prevent GraphQL type inference from crashing on this property
touchNode(getNode(node.fields.localFile))
}
})

if (
!online &&
process.env.GATSBY_CONTENTFUL_OFFLINE === `true` &&
process.env.NODE_ENV !== `production`
) {
getNodes().forEach(node => {
if (node.internal.owner !== `gatsby-source-contentful`) {
return
}
touchNode(node)
if (node.localFile___NODE) {
// Prevent GraphQL type inference from crashing on this property
touchNode(getNode(node.localFile___NODE))
}
})

return
}

Expand Down Expand Up @@ -188,7 +188,6 @@ export async function sourceNodes(
? n.internal.type !== `ContentfulTag`
: true)
)
existingNodes.forEach(n => touchNode(n))

// Report existing, new and updated nodes
const nodeCounts = {
Expand Down Expand Up @@ -254,8 +253,11 @@ export async function sourceNodes(
existingNodes
.filter(n => !newOrUpdatedEntries.has(`${n.id}___${n.sys.type}`))
.forEach(n => {
if (foreignReferenceMap[`${n.id}___${n.sys.type}`]) {
foreignReferenceMap[`${n.id}___${n.sys.type}`].forEach(
if (
n.contentful_id &&
foreignReferenceMap[`${n.contentful_id}___${n.sys.type}`]
) {
foreignReferenceMap[`${n.contentful_id}___${n.sys.type}`].forEach(
foreignReference => {
const { name, id } = foreignReference

Expand Down

0 comments on commit d43112f

Please sign in to comment.