-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
12 changed files
with
133 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: Dune | ||
slug: /dune | ||
--- | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,44 @@ | ||
const bioTemplate = require.resolve(`./src/templates/bio.js`) | ||
const postTemplate = require.resolve(`./src/templates/post.jsx`) | ||
|
||
exports.createPages = async ({ actions }) => { | ||
const { createPage } = actions | ||
createPage({ | ||
path: `/bio`, | ||
component: bioTemplate, | ||
exports.createPages = async ({ actions, graphql, reporter }) => { | ||
const { createPage } = actions | ||
|
||
const result = await graphql(` | ||
{ | ||
allMdx { | ||
nodes { | ||
id | ||
frontmatter { | ||
slug | ||
} | ||
internal { | ||
contentFilePath | ||
} | ||
} | ||
} | ||
} | ||
`) | ||
|
||
if (result.errors) { | ||
reporter.panicOnBuild(`There was an error loading your posts or pages`, result.errors) | ||
return | ||
} | ||
|
||
const posts = result.data.allMdx.nodes | ||
|
||
posts.forEach((post) => { | ||
createPage({ | ||
path: post.frontmatter.slug, | ||
component: `${postTemplate}?__contentFilePath=${post.internal.contentFilePath}`, | ||
context: { | ||
id: post.id, | ||
}, | ||
}) | ||
}) | ||
|
||
createPage({ | ||
path: `/bio`, | ||
component: bioTemplate, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
e2e-tests/themes/gatsby-theme-about/src/templates/post.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default function Post({ data, children }) { | ||
return ( | ||
<main> | ||
<h1 data-testid="post-template">{data.post.frontmatter.title}</h1> | ||
{children} | ||
</main> | ||
) | ||
} | ||
|
||
export const Head = () => <title>Post</title> | ||
|
||
export const query = graphql` | ||
query($id: String!) { | ||
post: mdx(id: { eq: $id }) { | ||
frontmatter { | ||
title | ||
} | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: Dune | ||
slug: /dune | ||
--- | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
e2e-tests/themes/production-runtime/src/gatsby-theme-about/templates/post.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from "react" | ||
import { graphql } from "gatsby" | ||
|
||
export default function Post({ data, children }) { | ||
return ( | ||
<main> | ||
<h1 data-testid="post-template">{`${data.post.frontmatter.titleAlias} - Shadowed`}</h1> | ||
{children} | ||
</main> | ||
) | ||
} | ||
|
||
export const query = graphql` | ||
query($id: String!) { | ||
post: mdx(id: { eq: $id }) { | ||
frontmatter { | ||
titleAlias: title | ||
} | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters