Skip to content

Commit cbb5161

Browse files
authored
Merge branch 'source' into patch-1
2 parents 6a5076e + e5b7204 commit cbb5161

File tree

118 files changed

+7248
-6657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+7248
-6657
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ jobs:
88
steps:
99
- uses: actions/checkout@v1
1010
- uses: actions/setup-node@v1
11+
with:
12+
node-version: '16.5.0'
1113

1214
- run: yarn install
1315

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,6 @@ yarn-error.log
7171

7272
# Swap files
7373
*.swp
74+
75+
# Codegen stuff
76+
src/__generated__/

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.5.0

LICENSE

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
LICENSE AGREEMENT For graphql.org software
1+
MIT License
22

3-
Facebook, Inc. (“Facebook”) owns all right, title and interest, including all
4-
intellectual property and other proprietary rights, in and to the graphql.org
5-
software. Subject to your compliance with these terms, you are hereby granted a
6-
non-exclusive, worldwide, royalty-free copyright license to (1) use and copy the
7-
graphql.org software; and (2) reproduce and distribute the graphql.org software
8-
as part of your own software (“Your Software”). Facebook reserves all rights not
9-
expressly granted to you in this license agreement.
3+
Copyright (c) GraphQL Contributors
104

11-
THE SOFTWARE AND DOCUMENTATION, IF ANY, ARE PROVIDED "AS IS" AND ANY EXPRESS OR
12-
IMPLIED WARRANTIES (INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
13-
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE) ARE DISCLAIMED. IN NO
14-
EVENT SHALL FACEBOOK OR ITS AFFILIATES, OFFICES, DIRECTORS OR EMPLOYEES BE
15-
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
16-
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
17-
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18-
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
19-
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
20-
THE USE OF THE SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
2111

22-
You will include in Your Software (e.g., in the file(s), documentation or other
23-
materials accompanying your software): (1) the disclaimer set forth above; (2)
24-
this sentence; and (3) the following copyright notice:
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
2514

26-
Copyright (c) 2015, Facebook, Inc. All rights reserved.
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

gatsby-config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = {
22
siteMetadata: {
3-
title: "A query language for your API",
3+
title: "GraphQL",
44
description:
5-
"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.",
5+
"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
},
88

@@ -115,5 +115,11 @@ module.exports = {
115115
],
116116
},
117117
},
118+
{
119+
resolve: "gatsby-plugin-typegen",
120+
options: {
121+
outputPath: "src/__generated__/gatsby-types.d.ts",
122+
},
123+
},
118124
],
119125
}

gatsby-node.js

Lines changed: 115 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,89 @@ const frontmatterParser = require("parser-front-matter")
55
const { readFile } = require("fs-extra")
66
const { promisify } = require("util")
77

8+
exports.createSchemaCustomization = ({ actions, schema }) => {
9+
const gql = String.raw;
10+
const { createTypes } = actions;
11+
12+
createTypes(gql`
13+
type BlogPost implements Node
14+
@childOf(types: ["MarkdownRemark"])
15+
{
16+
postId: String!
17+
title: String!
18+
tags: [String!]!
19+
date: Date! @dateformat(formatString: "YYYY-MM-DD")
20+
authors: [String!]!
21+
guestBio: String
22+
remark: MarkdownRemark! @link # backlink to the parent
23+
}
24+
`);
25+
};
26+
27+
// Transform nodes, each of logic inside here can be extracted to a separated plugin later.
28+
exports.onCreateNode = async ({
29+
reporter,
30+
node,
31+
actions,
32+
createNodeId,
33+
createContentDigest,
34+
}) => {
35+
const { createNode, createParentChildLink } = actions;
36+
37+
// Derive content nodes from remark nodes
38+
if (node.internal.type === 'MarkdownRemark') {
39+
if (node.frontmatter.layout === 'blog') {
40+
const nodeId = createNodeId(`${node.id} >>> BlogPost`);
41+
42+
const permalink = node.frontmatter.permalink;
43+
if (!permalink?.startsWith('/blog/')) {
44+
reporter.panicOnBuild(`${permalink} is not valid permalink for blog post`);
45+
return;
46+
}
47+
48+
// It contains a kind of transform logic. However, those logics can be extracted to resolvers into ahead of sourcing (createTypes)
49+
const blogPostContent = {
50+
id: nodeId,
51+
postId: permalink.replace('/blog/', '').replace(/\/$/, ''),
52+
title: node.frontmatter.title,
53+
tags: node.frontmatter.tags ?? [],
54+
date: node.frontmatter.date,
55+
authors: (node.frontmatter.byline ?? '')
56+
.split(',')
57+
.map(name => name.trim())
58+
.filter(Boolean),
59+
guestBio: node.frontmatter.guestBio ?? null,
60+
};
61+
62+
createNode({
63+
...blogPostContent,
64+
remark: node.id,
65+
parent: node.id,
66+
children: [],
67+
internal: {
68+
type: 'BlogPost',
69+
contentDigest: createContentDigest(blogPostContent),
70+
},
71+
});
72+
73+
createParentChildLink({
74+
parent: node,
75+
child: blogPostContent,
76+
});
77+
}
78+
}
79+
};
80+
881
exports.onCreatePage = async ({ page, actions }) => {
82+
// trying to refactor code to be "the Gatsby way".
83+
// from the paths on ready, ignores a bunch of existing custom logic below.
84+
if (page.path.startsWith('/blog')) {
85+
return;
86+
}
87+
if (page.path.startsWith('/tags')) {
88+
return;
89+
}
90+
991
const { createPage, deletePage } = actions
1092
deletePage(page)
1193
let context = {
@@ -148,8 +230,8 @@ exports.createPages = async ({ graphql, actions }) => {
148230
}
149231
}
150232
}
151-
tagsGroup: allMarkdownRemark {
152-
group(field: frontmatter___tags) {
233+
allBlogPost {
234+
group(field: tags) {
153235
fieldValue
154236
}
155237
}
@@ -164,6 +246,17 @@ exports.createPages = async ({ graphql, actions }) => {
164246
throw result.errors
165247
}
166248

249+
const tags = result.data.allBlogPost.group.map(group => group.fieldValue)
250+
tags.forEach(tag => {
251+
createPage({
252+
path: `/tags/${tag.toLowerCase()}/`,
253+
component: path.resolve("./src/templates/{BlogPost.tags}.tsx"),
254+
context: {
255+
tag,
256+
},
257+
})
258+
})
259+
167260
const markdownPages = result.data.allMarkdownRemark.edges
168261

169262
// foundation: [
@@ -201,6 +294,15 @@ exports.createPages = async ({ graphql, actions }) => {
201294
category: "GraphQL Foundation",
202295
},
203296
},
297+
{
298+
frontmatter: {
299+
sidebarTitle: "GraphQL Landscape",
300+
title: "GraphQL Landscape",
301+
permalink: "https://landscape.graphql.org/",
302+
date: null,
303+
category: "GraphQL Foundation",
304+
},
305+
},
204306
],
205307
},
206308
],
@@ -341,7 +443,9 @@ exports.createPages = async ({ graphql, actions }) => {
341443

342444
// Use all the set up data to now tell Gatsby to create pages
343445
// on the site
344-
allPages.forEach(page => {
446+
allPages
447+
.filter(page => !page.permalink.startsWith('/blog'))
448+
.forEach(page => {
345449
createPage({
346450
path: `${page.permalink}`,
347451
component: docTemplate,
@@ -353,17 +457,14 @@ exports.createPages = async ({ graphql, actions }) => {
353457
},
354458
})
355459
})
460+
}
356461

357-
// Create tag pages
358-
const tagTemplate = path.resolve("src/templates/tags.tsx")
359-
const tags = result.data.tagsGroup.group
360-
tags.forEach(tag => {
361-
createPage({
362-
path: `/tags/${tag.fieldValue}/`,
363-
component: tagTemplate,
364-
context: {
365-
tag: tag.fieldValue,
366-
},
367-
})
462+
exports.onCreateWebpackConfig = ({ actions }) => {
463+
actions.setWebpackConfig({
464+
resolve: {
465+
fallback: {
466+
"assert": require.resolve("assert/"),
467+
}
468+
}
368469
})
369470
}

package.json

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,42 @@
1111
"clean": "gatsby clean",
1212
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
1313
},
14+
"resolutions": {
15+
"graphql": "15.6.0"
16+
},
1417
"dependencies": {
15-
"@graphql-tools/schema": "7.0.0",
16-
"@weknow/gatsby-remark-twitter": "^0.2.3",
17-
"codemirror": "5.58.2",
18-
"codemirror-graphql": "0.12.3",
19-
"gatsby": "2.25.0",
20-
"gatsby-plugin-anchor-links": "1.1.1",
21-
"gatsby-plugin-feed": "2.6.0",
22-
"gatsby-plugin-google-analytics": "2.4.0",
23-
"gatsby-plugin-less": "4.0.6",
24-
"gatsby-plugin-react-helmet": "3.3.14",
25-
"gatsby-plugin-webfonts": "1.1.3",
26-
"gatsby-source-filesystem": "2.4.0",
27-
"gatsby-transformer-remark": "2.9.0",
28-
"globby": "11.0.1",
29-
"graphql": "15.4.0",
30-
"marked": "1.2.2",
31-
"numbro": "2.3.2",
18+
"@graphql-tools/schema": "8.2.0",
19+
"@reach/router": "1.3.4",
20+
"@weknow/gatsby-remark-twitter": "0.2.3",
21+
"assert": "2.0.0",
22+
"codemirror": "5.63.3",
23+
"codemirror-graphql": "1.0.2",
24+
"gatsby": "3.14.3",
25+
"gatsby-plugin-anchor-links": "1.2.1",
26+
"gatsby-plugin-feed": "3.14.0",
27+
"gatsby-plugin-google-analytics": "3.14.0",
28+
"gatsby-plugin-less": "5.14.0",
29+
"gatsby-plugin-react-helmet": "4.14.0",
30+
"gatsby-plugin-typegen": "2.2.4",
31+
"gatsby-plugin-webfonts": "2.1.1",
32+
"gatsby-source-filesystem": "3.14.0",
33+
"gatsby-transformer-remark": "4.11.0",
34+
"globby": "11.0.4",
35+
"graphql": "15.6.0",
36+
"marked": "3.0.7",
37+
"numbro": "2.3.5",
3238
"parser-front-matter": "1.6.4",
33-
"prism-react-renderer": "1.1.1",
34-
"prismjs": "1.22.0",
35-
"react": "17.0.1",
36-
"react-dom": "17.0.1",
39+
"prism-react-renderer": "1.2.1",
40+
"prismjs": "1.25.0",
41+
"react": "17.0.2",
42+
"react-dom": "17.0.2",
3743
"react-helmet": "6.1.0",
3844
"timeago.js": "4.0.2"
3945
},
4046
"devDependencies": {
41-
"@types/codemirror": "0.0.98",
42-
"@types/prismjs": "1.16.2",
43-
"@types/react-helmet": "6.1.0",
44-
"prettier": "2.1.2"
47+
"@types/codemirror": "5.60.5",
48+
"@types/prismjs": "1.16.6",
49+
"@types/react-helmet": "6.1.4",
50+
"prettier": "2.4.1"
4551
}
4652
}

renovate.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": [
3+
"config:base"
4+
]
5+
}

0 commit comments

Comments
 (0)