-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.ts
81 lines (74 loc) · 1.84 KB
/
gatsby-node.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { GatsbyNode } from "gatsby";
import path from "path";
/** The bug occurs with or without these typings, but this is similar to how our project is typed */
export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"] =
({ actions }) => {
actions.createTypes(`
type MarkdownRemarkFrontmatter {
image: File @fileByRelativePath
alt: String
}
`);
};
export const createPages: GatsbyNode["createPages"] = async ({
actions,
graphql,
}) => {
// BUG REPRO DETAIL:
// 1. This query produces the bug, following the README steps
const result = await graphql<{
pages: { edges: { node: { frontmatter: object } }[] };
}>(`
{
pages: allMarkdownRemark(
filter: {
fileAbsolutePath: { regex: "/.*/cms/content/pages/home.md/" }
}
) {
edges {
node {
frontmatter {
slug
heading
image {
childImageSharp {
gatsbyImageData
}
}
alt
}
}
}
}
}
`);
const context = result.data?.pages.edges?.[0].node.frontmatter;
// 2. HOWEVER this query succeeds:
/*
const result = await graphql<{ markdownRemark: { frontmatter: object } }>(`
{
markdownRemark(frontmatter: { slug: { eq: "home" } }) {
frontmatter {
slug
heading
image {
childImageSharp {
gatsbyImageData
}
}
alt
}
}
}
`);
const context = result?.data?.markdownRemark?.frontmatter;
*/
if (!context) {
return Promise.reject(`query failed ${JSON.stringify(result, null, 2)}`);
}
actions.createPage({
path: "/",
component: path.resolve(`src/templates/page.tsx`),
context,
});
};