Skip to content

Commit 703844f

Browse files
authored
feat: enable head component and native typegen (graphql#1292)
* feat: enable head component and native typegen * remove forgotten title
1 parent af5e4f6 commit 703844f

File tree

20 files changed

+2566
-1894
lines changed

20 files changed

+2566
-1894
lines changed

.prettierrc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"arrowParens": "avoid",
3-
"semi": false
4-
}
3+
"semi": false,
4+
"singleQuote": false
5+
}

gatsby-config.js

+9-15
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ module.exports = {
55
"A query language for your API — GraphQL provides a complete description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.",
66
siteUrl: "http://graphql.org/",
77
},
8-
8+
graphqlTypegen: {
9+
typesOutputPath: `src/__generated__/gatsby-types.d.ts`,
10+
},
911
plugins: [
10-
"gatsby-plugin-react-helmet",
11-
'gatsby-plugin-anchor-links',
12+
"gatsby-plugin-anchor-links",
1213
{
1314
resolve: "gatsby-source-filesystem",
1415
options: {
@@ -23,11 +24,11 @@ module.exports = {
2324
{
2425
resolve: "@weknow/gatsby-remark-twitter",
2526
options: {
26-
debug: true
27-
}
28-
}
29-
]
30-
}
27+
debug: true,
28+
},
29+
},
30+
],
31+
},
3132
},
3233
{
3334
resolve: `gatsby-plugin-webfonts`,
@@ -51,7 +52,6 @@ module.exports = {
5152
},
5253
},
5354
`gatsby-plugin-less`,
54-
`gatsby-plugin-react-helmet`,
5555
{
5656
resolve: `gatsby-plugin-google-analytics`,
5757
options: {
@@ -115,11 +115,5 @@ module.exports = {
115115
],
116116
},
117117
},
118-
{
119-
resolve: "gatsby-plugin-typegen",
120-
options: {
121-
outputPath: "src/__generated__/gatsby-types.d.ts",
122-
},
123-
},
124118
],
125119
}

package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
"assert": "2.0.0",
2222
"codemirror": "5.65.1",
2323
"codemirror-graphql": "1.2.11",
24-
"gatsby": "4.7.2",
24+
"gatsby": "4.24.8",
2525
"gatsby-plugin-anchor-links": "1.2.1",
2626
"gatsby-plugin-feed": "4.7.0",
2727
"gatsby-plugin-google-analytics": "4.7.0",
2828
"gatsby-plugin-less": "6.7.0",
29-
"gatsby-plugin-react-helmet": "5.7.0",
3029
"gatsby-plugin-typegen": "2.2.4",
3130
"gatsby-plugin-webfonts": "2.2.1",
3231
"gatsby-source-filesystem": "4.7.0",
@@ -40,13 +39,11 @@
4039
"prismjs": "1.25.0",
4140
"react": "17.0.2",
4241
"react-dom": "17.0.2",
43-
"react-helmet": "6.1.0",
4442
"timeago.js": "4.0.2"
4543
},
4644
"devDependencies": {
4745
"@types/codemirror": "5.60.5",
4846
"@types/prismjs": "1.16.6",
49-
"@types/react-helmet": "6.1.4",
5047
"prettier": "2.4.1"
5148
}
52-
}
49+
}

src/components/BlogLayout/index.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ export const fragments = graphql`
77
fragment BlogLayout_post on BlogPost {
88
...BlogPost_post
99
}
10-
`;
10+
`
1111

1212
interface Props {
13-
post: GatsbyTypes.BlogLayout_postFragment,
13+
post: Queries.BlogLayout_postFragment
1414
}
1515

16-
const BlogLayout: React.FC<Props> = ({
17-
post,
18-
}) => {
16+
const BlogLayout: React.FC<Props> = ({ post }) => {
1917
return (
2018
<section>
2119
<div className="documentationContent">

src/components/BlogPost/index.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ export const fragments = graphql`
1313
rawMarkdownBody
1414
}
1515
}
16-
`;
16+
`
1717

1818
interface Props {
19-
post: GatsbyTypes.BlogPost_postFragment,
19+
post: Queries.BlogPost_postFragment
2020
}
2121

22-
const BlogPost: React.FC<Props> = ({
23-
post,
24-
}) => {
25-
const byline = post.authors.join(', ')
22+
const BlogPost: React.FC<Props> = ({ post }) => {
23+
const byline = post.authors.join(", ")
2624
return (
2725
<div className="inner-content">
2826
<h1>{post.title}</h1>

src/components/BlogPostPreview/index.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@ export const fragments = graphql`
1212
excerpt
1313
}
1414
}
15-
`;
15+
`
1616

1717
interface Props {
18-
post: GatsbyTypes.BlogPostPreview_postFragment,
18+
post: Queries.BlogPostPreview_postFragment
1919
}
2020

21-
const BlogPostPreview: React.FC<Props> = ({
22-
post,
23-
}) => (
21+
const BlogPostPreview: React.FC<Props> = ({ post }) => (
2422
<div className="inner-content">
2523
<h1>
2624
<Link to={post.postPath!}>{post.title}</Link>
2725
</h1>
2826

2927
<p>
30-
{new Date(post.date).toLocaleDateString()} by {post.authors.join(', ')}
28+
{new Date(post.date).toLocaleDateString()} by {post.authors.join(", ")}
3129
</p>
3230

3331
<div className="tag-wrapper">

src/components/BlogSidebar/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { Link, useStaticQuery, graphql } from "gatsby"
33
import { useLocation } from "@reach/router"
44

55
const BlogSidebar: React.FC = () => {
6-
const data = useStaticQuery<GatsbyTypes.AllTagsStaticQuery>(graphql`
6+
const data = useStaticQuery<Queries.AllTagsStaticQuery>(graphql`
77
query AllTagsStatic {
88
allBlogPost {
99
group(field: tags) {
1010
fieldValue
1111
}
1212
}
1313
allRecentBlogPost: allBlogPost(
14-
limit: 30,
14+
limit: 30
1515
sort: { fields: [date], order: DESC }
1616
) {
1717
nodes {
@@ -26,7 +26,7 @@ const BlogSidebar: React.FC = () => {
2626
const tags = data.allBlogPost.group.map(group => group.fieldValue!)
2727
const recentPosts = data.allRecentBlogPost.nodes
2828

29-
const { pathname: currentPath } = useLocation();
29+
const { pathname: currentPath } = useLocation()
3030

3131
return (
3232
<div className="nav-docs blog-sidebar">
@@ -41,7 +41,7 @@ const BlogSidebar: React.FC = () => {
4141
<ul>
4242
{tags.map(tag => {
4343
const formattedTag = tag[0].toUpperCase() + tag.substring(1)
44-
const pathname = `/tags/${tag}/`;
44+
const pathname = `/tags/${tag}/`
4545
return (
4646
<li key={tag}>
4747
{pathname === currentPath ? (

src/components/Layout/index.tsx

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11
import React from "react"
22
import Footer from "../Footer"
33
import Header from "../Header"
4-
import Seo from "../Seo"
54

65
import "../../assets/css/style.less"
76

8-
interface PageContext {
9-
sourcePath?: string
10-
}
11-
127
interface Props {
138
children: React.ReactNode
14-
title?: string
15-
description?: string
169
className?: string
17-
pageContext: PageContext
10+
pageContext?: { sourcePath?: string }
1811
}
1912
const IndexLayout = ({
20-
title,
21-
description,
2213
children,
2314
className,
24-
pageContext: { sourcePath },
15+
pageContext: { sourcePath } = {},
2516
}: Props): JSX.Element => (
2617
<>
27-
<Seo title={title} description={description} />
2818
<div className={className}>
2919
<Header />
3020
{children}

src/components/Seo/index.tsx

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from "react"
2-
import Helmet from "react-helmet"
32
import { useStaticQuery, graphql } from "gatsby"
43

54
interface Props {
@@ -8,7 +7,7 @@ interface Props {
87
}
98

109
const Seo = ({ title, description }: Props): JSX.Element => {
11-
const data = useStaticQuery<GatsbyTypes.SeoQueryQuery>(graphql`
10+
const data = useStaticQuery<Queries.SeoQueryQuery>(graphql`
1211
query SeoQuery {
1312
site {
1413
siteMetadata {
@@ -19,16 +18,16 @@ const Seo = ({ title, description }: Props): JSX.Element => {
1918
}
2019
`)
2120

22-
const metadata = data.site.siteMetadata
21+
const metadata = data.site!.siteMetadata
2322

2423
return (
25-
<Helmet>
26-
<title>{title ?? metadata.title}</title>
27-
<meta name="description" content={description ?? metadata.description} />
24+
<>
25+
<title>{title ?? metadata!.title}</title>
26+
<meta name="description" content={description ?? metadata!.description} />
2827
<meta property="og:image" content="/img/og-image.png" />
2928
<meta property="twitter:site" content="@graphql" />
3029
<meta name="viewport" content="width=640" />
31-
</Helmet>
30+
</>
3231
)
3332
}
3433

src/pages/blog.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import type { PageProps } from "gatsby"
44
import Layout from "../components/Layout"
55
import BlogPostPreview from "../components/BlogPostPreview"
66
import BlogSidebar from "../components/BlogSidebar"
7+
import Seo from "../components/Seo"
78

89
export const query = graphql`
910
query BlogPostListPage {
10-
allBlogPost(
11-
sort: { fields: [date], order: DESC }
12-
) {
11+
allBlogPost(sort: { fields: [date], order: DESC }) {
1312
nodes {
1413
id
1514
...BlogPostPreview_post
@@ -18,19 +17,16 @@ export const query = graphql`
1817
}
1918
`
2019

21-
type Props = PageProps<GatsbyTypes.BlogPostListPageQuery, GatsbyTypes.SitePageContext>
20+
type Props = PageProps<Queries.BlogPostListPageQuery>
2221

2322
const BlogPostListPage: React.FC<Props> = ({ data }) => {
2423
return (
25-
<Layout title="Blog | GraphQL" pageContext={{}}>
24+
<Layout>
2625
<section>
2726
<div className="documentationContent">
2827
<div>
2928
{data.allBlogPost.nodes.map(post => (
30-
<BlogPostPreview
31-
key={post.id}
32-
post={post}
33-
/>
29+
<BlogPostPreview key={post.id} post={post} />
3430
))}
3531
</div>
3632
<BlogSidebar />
@@ -40,4 +36,8 @@ const BlogPostListPage: React.FC<Props> = ({ data }) => {
4036
)
4137
}
4238

39+
export function Head() {
40+
return <Seo title="Blog | GraphQL" />
41+
}
42+
4343
export default BlogPostListPage

src/pages/blog/{BlogPost.postId}.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as React from "react"
2-
import type { PageProps } from "gatsby"
2+
import type { PageProps, HeadProps } from "gatsby"
33
import { graphql } from "gatsby"
44
import Layout from "../../components/Layout"
55
import BlogLayout from "../../components/BlogLayout"
6+
import Seo from "../../components/Seo"
67

78
export const query = graphql`
89
query BlogPostPage($id: String!) {
@@ -13,19 +14,21 @@ export const query = graphql`
1314
}
1415
`
1516

16-
type Props = PageProps<GatsbyTypes.BlogPostPageQuery, GatsbyTypes.SitePageContext>
17+
type Props = PageProps<Queries.BlogPostPageQuery>
1718

18-
const BlogPostPage: React.FC<Props> = ({
19-
data
20-
}) => {
19+
const BlogPostPage: React.FC<Props> = ({ data }) => {
2120
// Always exist since it is collected by Gatsby filesystem route API
2221
const post = data.blogPost!
2322

2423
return (
25-
<Layout title={`${post.title} | GraphQL`} pageContext={{}}>
24+
<Layout>
2625
<BlogLayout post={post} />
2726
</Layout>
2827
)
2928
}
3029

30+
export function Head({ data }: HeadProps<Queries.BlogPostPageQuery>) {
31+
return <Seo title={`${data.blogPost!.title} | GraphQL`} />
32+
}
33+
3134
export default BlogPostPage

src/pages/brand.tsx

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import React, { useState } from "react"
22
import type { PageProps } from "gatsby"
33
import Layout from "../components/Layout"
4+
import Seo from "../components/Seo"
45

5-
export default ({ pageContext }: PageProps<object, GatsbyTypes.SitePageContext>) => {
6+
export default ({ pageContext }: PageProps<{}, { sourcePath: string }>) => {
67
return (
7-
<Layout
8-
title="GraphQL logo, brand guidelines and assets"
9-
pageContext={pageContext}
10-
className="brand"
11-
>
8+
<Layout pageContext={pageContext} className="brand">
129
<section>
1310
<h1>GraphQL Logo &amp; Brand Guidelines</h1>
1411
<div className="agree-actions-container top">
@@ -24,8 +21,11 @@ export default ({ pageContext }: PageProps<object, GatsbyTypes.SitePageContext>)
2421
GraphQL Foundation
2522
</a>
2623
. Use of the trademark and logo are subject to the{" "}
27-
<a href="https://lfprojects.org/policies/trademark-policy/"
28-
target="_blank">LF Projects trademark policy
24+
<a
25+
href="https://lfprojects.org/policies/trademark-policy/"
26+
target="_blank"
27+
>
28+
LF Projects trademark policy
2929
</a>
3030
.
3131
</p>
@@ -418,6 +418,10 @@ export default ({ pageContext }: PageProps<object, GatsbyTypes.SitePageContext>)
418418
)
419419
}
420420

421+
export function Head() {
422+
return <Seo title="GraphQL logo, brand guidelines and assets" />
423+
}
424+
421425
function AgreeActions() {
422426
const [agree, setAgree] = useState(false)
423427
return (

0 commit comments

Comments
 (0)