Skip to content

Commit dc998d5

Browse files
authored
fix(gatsby): Shadowing with resourceQuery (#37938)
* the actual fix * actual actual fix * test setup with mdx * test assertion * fix development-runtime * test test * revert files that i didn't want to commit * fix dev, too
1 parent 0e9feeb commit dc998d5

File tree

12 files changed

+133
-15
lines changed

12 files changed

+133
-15
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,15 @@ jobs:
392392
- run: echo 'export CYPRESS_RECORD_KEY="${CY_CLOUD_THEMES_DEV_RUNTIME}"' >> "$BASH_ENV"
393393
- e2e-test:
394394
test_path: e2e-tests/themes
395-
test_command: cd development-runtime; yarn test
395+
test_command: cd development-runtime; gatsby-dev --force-install --scan-once; yarn test
396396

397397
themes_e2e_tests_production_runtime:
398398
<<: *e2e-executor
399399
steps:
400400
- run: echo 'export CYPRESS_RECORD_KEY="${CY_CLOUD_THEMES_PROD_RUNTIME}"' >> "$BASH_ENV"
401401
- e2e-test:
402402
test_path: e2e-tests/themes
403-
test_command: cd production-runtime; yarn test
403+
test_command: cd production-runtime; gatsby-dev --force-install --scan-once; yarn test
404404

405405
e2e_tests_mdx:
406406
<<: *e2e-executor
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Dune
3+
slug: /dune
4+
---
5+
6+
Dune is set in the distant future amidst a feudal interstellar society in which various noble houses control planetary fiefs. It tells the story of young Paul Atreides, whose family accepts the stewardship of the planet Arrakis.

e2e-tests/themes/development-runtime/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"scripts": {
1414
"build": "gatsby build",
1515
"develop": "gatsby develop",
16+
"clean": "gatsby clean",
1617
"format": "prettier --write \"src/**/*.js\"",
1718
"serve": "gatsby serve",
1819
"start": "npm run develop",

e2e-tests/themes/gatsby-theme-about/gatsby-config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,13 @@ module.exports = {
1111
path: `${__dirname}/src/pages`,
1212
},
1313
},
14+
{
15+
resolve: `gatsby-source-filesystem`,
16+
options: {
17+
name: `posts`,
18+
path: `./content/posts`,
19+
},
20+
},
21+
`gatsby-plugin-mdx`,
1422
],
1523
}
Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
11
const bioTemplate = require.resolve(`./src/templates/bio.js`)
2+
const postTemplate = require.resolve(`./src/templates/post.jsx`)
23

3-
exports.createPages = async ({ actions }) => {
4-
const { createPage } = actions
5-
createPage({
6-
path: `/bio`,
7-
component: bioTemplate,
4+
exports.createPages = async ({ actions, graphql, reporter }) => {
5+
const { createPage } = actions
6+
7+
const result = await graphql(`
8+
{
9+
allMdx {
10+
nodes {
11+
id
12+
frontmatter {
13+
slug
14+
}
15+
internal {
16+
contentFilePath
17+
}
18+
}
19+
}
20+
}
21+
`)
22+
23+
if (result.errors) {
24+
reporter.panicOnBuild(`There was an error loading your posts or pages`, result.errors)
25+
return
26+
}
27+
28+
const posts = result.data.allMdx.nodes
29+
30+
posts.forEach((post) => {
31+
createPage({
32+
path: post.frontmatter.slug,
33+
component: `${postTemplate}?__contentFilePath=${post.internal.contentFilePath}`,
34+
context: {
35+
id: post.id,
36+
},
837
})
38+
})
39+
40+
createPage({
41+
path: `/bio`,
42+
component: bioTemplate,
43+
})
944
}

e2e-tests/themes/gatsby-theme-about/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
},
1919
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/e2e-tests/themes/gatsby-theme-about#readme",
2020
"dependencies": {
21+
"@mdx-js/react": "^2.3.0",
2122
"gatsby": "next",
22-
"gatsby-plugin-page-creator": "next"
23+
"gatsby-plugin-mdx": "next",
24+
"gatsby-plugin-page-creator": "next",
25+
"gatsby-source-filesystem": "next"
2326
},
2427
"devDependencies": {
2528
"prettier": "2.8.7"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from "react"
2+
import { graphql } from "gatsby"
3+
4+
export default function Post({ data, children }) {
5+
return (
6+
<main>
7+
<h1 data-testid="post-template">{data.post.frontmatter.title}</h1>
8+
{children}
9+
</main>
10+
)
11+
}
12+
13+
export const Head = () => <title>Post</title>
14+
15+
export const query = graphql`
16+
query($id: String!) {
17+
post: mdx(id: { eq: $id }) {
18+
frontmatter {
19+
title
20+
}
21+
}
22+
}
23+
`
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Dune
3+
slug: /dune
4+
---
5+
6+
Dune is set in the distant future amidst a feudal interstellar society in which various noble houses control planetary fiefs. It tells the story of young Paul Atreides, whose family accepts the stewardship of the planet Arrakis.

e2e-tests/themes/production-runtime/cypress/integration/pages.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ describe(`Pages`, () => {
2828
cy.visit(`/about`).waitForRouteChange()
2929
cy.getTestElement(`author`).contains(`Sidhartha Chatterjee`)
3030
})
31+
it(`page templates with resourceQuery can be shadowed`, () => {
32+
cy.visit(`/dune`).waitForRouteChange()
33+
cy.getTestElement(`post-template`).contains(`Dune - Shadowed`)
34+
})
3135
})

e2e-tests/themes/production-runtime/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"scripts": {
1414
"build": "gatsby build",
1515
"develop": "gatsby develop",
16+
"clean": "gatsby clean",
1617
"format": "prettier --write \"src/**/*.js\"",
1718
"serve": "gatsby serve",
1819
"start": "npm run develop",

0 commit comments

Comments
 (0)