Skip to content

Commit 294c3c3

Browse files
authored
Merge pull request #222 from kontent-ai/gatsby-v5
Gatsby v5
2 parents 60d1d7d + 5e400ac commit 294c3c3

28 files changed

+27538
-30149
lines changed

examples/dsg-ssr/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
},
3131
"homepage": "https://github.com/kontent-ai/gatsby-packages/tree/master/examples/dsg-ssr#readme",
3232
"dependencies": {
33-
"gatsby": "^4.20.0",
33+
"gatsby": "^5.2.0",
3434
"react": "^18.2.0",
3535
"react-dom": "^18.2.0"
3636
},

examples/navigation/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"test": "echo \"Write tests - eventually! -> https://gatsby.dev/unit-testing\" && exit 0"
1515
},
1616
"dependencies": {
17-
"gatsby": "^4.2.0",
17+
"gatsby": "^5.2.0",
1818
"react": "^18.2.0",
1919
"react-dom": "^18.2.0"
2020
},
Lines changed: 76 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,76 @@
1-
const {
2-
getKontentItemNodeTypeName,
3-
} = require("@kontent-ai/gatsby-source")
4-
5-
const linkLanguageVariants = (api, typeCodename) => {
6-
const {
7-
actions: { createTypes },
8-
schema,
9-
} = api
10-
11-
// i.e. article -> kontent_item_article
12-
const type = getKontentItemNodeTypeName(typeCodename)
13-
14-
const extendedType = schema.buildObjectType({
15-
name: type,
16-
fields: {
17-
fallback_used: {
18-
type: "Boolean",
19-
// https://www.gatsbyjs.org/docs/schema-customization/
20-
resolve: (source) => {
21-
return source.preferred_language !== source.system.language
22-
},
23-
},
24-
other_languages: {
25-
type: `[${type}]`,
26-
// https://www.gatsbyjs.org/docs/schema-customization/
27-
resolve: async (source, _args, context, _info) => {
28-
const pluginInfo = await context.nodeModel.runQuery({
29-
query: {
30-
filter: {
31-
name: {
32-
eq: "@kontent-ai/gatsby-source",
33-
},
34-
},
35-
},
36-
type: "SitePlugin",
37-
firstOnly: true,
38-
})
39-
40-
const otherLanguageCodenames = pluginInfo.pluginOptions.languageCodenames.filter(
41-
lang => lang !== source.system.language // filter out the actual language variants
42-
)
43-
44-
const promises = otherLanguageCodenames.map(otherLanguage => context.nodeModel.runQuery({
45-
query: {
46-
filter: {
47-
system: {
48-
codename: {
49-
eq: source.system.codename,
50-
},
51-
// It is possible to skip this filter, if you want to include the fallback nodes to the other_languages property
52-
language: {
53-
eq: otherLanguage
54-
}
55-
},
56-
preferred_language: {
57-
eq: otherLanguage,
58-
},
59-
},
60-
},
61-
type: type,
62-
firstOnly: true,
63-
}))
64-
65-
const otherLanguageNodes = await Promise
66-
.all(promises);
67-
return otherLanguageNodes
68-
.filter(item => item != null);
69-
},
70-
},
71-
},
72-
})
73-
createTypes(extendedType)
74-
}
75-
76-
module.exports = {
77-
linkLanguageVariants,
78-
}
1+
const {
2+
getKontentItemNodeTypeName,
3+
} = require("@kontent-ai/gatsby-source")
4+
5+
const linkLanguageVariants = (api, typeCodename) => {
6+
const {
7+
actions: { createTypes },
8+
schema,
9+
} = api
10+
11+
// i.e. article -> kontent_item_article
12+
const type = getKontentItemNodeTypeName(typeCodename)
13+
14+
const extendedType = schema.buildObjectType({
15+
name: type,
16+
fields: {
17+
fallback_used: {
18+
type: "Boolean",
19+
// https://www.gatsbyjs.org/docs/schema-customization/
20+
resolve: (source) => {
21+
return source.preferred_language !== source.system.language
22+
},
23+
},
24+
other_languages: {
25+
type: `[${type}]`,
26+
// https://www.gatsbyjs.org/docs/schema-customization/
27+
resolve: async (source, _args, context, _info) => {
28+
const pluginInfo = await context.nodeModel.findOne({
29+
query: {
30+
filter: {
31+
name: {
32+
eq: "@kontent-ai/gatsby-source",
33+
},
34+
},
35+
},
36+
type: "SitePlugin",
37+
})
38+
39+
const otherLanguageCodenames = pluginInfo.pluginOptions.languageCodenames.filter(
40+
lang => lang !== source.system.language // filter out the actual language variants
41+
)
42+
43+
const promises = otherLanguageCodenames.map(otherLanguage => context.nodeModel.findOne({
44+
query: {
45+
filter: {
46+
system: {
47+
codename: {
48+
eq: source.system.codename,
49+
},
50+
// It is possible to skip this filter, if you want to include the fallback nodes to the other_languages property
51+
language: {
52+
eq: otherLanguage
53+
}
54+
},
55+
preferred_language: {
56+
eq: otherLanguage,
57+
},
58+
},
59+
},
60+
type: type
61+
}))
62+
63+
const otherLanguageNodes = await Promise
64+
.all(promises);
65+
return otherLanguageNodes
66+
.filter(item => item != null);
67+
},
68+
},
69+
},
70+
})
71+
createTypes(extendedType)
72+
}
73+
74+
module.exports = {
75+
linkLanguageVariants,
76+
}

examples/relationships/gatsby-node.js

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
1-
2-
const { linkLanguageVariants } = require("./example-languages-variants")
3-
const {
4-
linkUsedByContentItems,
5-
} = require("./example-used-by-content-item-link")
6-
7-
exports.createSchemaCustomization = async api => {
8-
linkLanguageVariants(api, "article")
9-
linkUsedByContentItems(api, "article", "tag", "tags", "used_by_articles")
10-
}
11-
12-
exports.createPages = async ({ graphql, actions }) => {
13-
const { createPage, createRedirect } = actions
14-
15-
const { data: { sitePlugin: { pluginOptions } } } = await graphql(`
16-
query SiteLanguages {
17-
sitePlugin(name: {eq: "@kontent-ai/gatsby-source"}) {
18-
pluginOptions
19-
}
20-
}
21-
`)
22-
23-
const { languageCodenames } = pluginOptions;
24-
languageCodenames.forEach(language => {
25-
createPage({
26-
path: `${language}/articles`,
27-
component: require.resolve(`./src/templates/articles.js`),
28-
context: {
29-
language: language,
30-
},
31-
})
32-
});
33-
34-
createRedirect({
35-
fromPath: '/articles',
36-
toPath: `/${languageCodenames[0]}/articles`,
37-
redirectInBrowser: true,
38-
isPermanent: true
39-
})
40-
41-
42-
const { data } = await graphql(`
43-
{
44-
allKontentItemArticle(filter: {fallback_used: {eq: false}}) {
45-
nodes {
46-
preferred_language
47-
system {
48-
codename
49-
}
50-
elements {
51-
slug {
52-
value
53-
}
54-
}
55-
}
56-
}
57-
}
58-
`)
59-
60-
const { allKontentItemArticle: { nodes: articlesData } } = data;
61-
62-
articlesData.forEach(article => {
63-
createPage({
64-
path: `${article.preferred_language}/articles/${article.elements.slug.value}`,
65-
component: require.resolve(`./src/templates/article-detail.js`),
66-
context: {
67-
codename: article.system.codename,
68-
language: article.preferred_language,
69-
},
70-
})
71-
});
72-
}
1+
2+
const { linkLanguageVariants } = require("./example-languages-variants")
3+
const {
4+
linkUsedByContentItems,
5+
} = require("./example-used-by-content-item-link")
6+
7+
exports.createSchemaCustomization = async api => {
8+
linkLanguageVariants(api, "article")
9+
linkUsedByContentItems(api, "article", "tag", "tags", "used_by_articles")
10+
}
11+
12+
exports.createPages = async ({ graphql, actions }) => {
13+
const { createPage, createRedirect } = actions
14+
15+
const { data: { sitePlugin: { pluginOptions } } } = await graphql(`
16+
query SiteLanguages {
17+
sitePlugin(name: {eq: "@kontent-ai/gatsby-source"}) {
18+
pluginOptions
19+
}
20+
}
21+
`)
22+
23+
const { languageCodenames } = pluginOptions;
24+
languageCodenames.forEach(language => {
25+
createPage({
26+
path: `${language}/articles`,
27+
component: require.resolve(`./src/templates/articles.js`),
28+
context: {
29+
language: language,
30+
},
31+
})
32+
});
33+
34+
createRedirect({
35+
fromPath: '/articles/',
36+
toPath: `/${languageCodenames[0]}/articles/`,
37+
redirectInBrowser: true,
38+
isPermanent: true
39+
})
40+
41+
42+
const { data } = await graphql(`
43+
{
44+
allKontentItemArticle(filter: {fallback_used: {eq: false}}) {
45+
nodes {
46+
preferred_language
47+
system {
48+
codename
49+
}
50+
elements {
51+
slug {
52+
value
53+
}
54+
}
55+
}
56+
}
57+
}
58+
`)
59+
60+
const { allKontentItemArticle: { nodes: articlesData } } = data;
61+
62+
articlesData.forEach(article => {
63+
createPage({
64+
path: `${article.preferred_language}/articles/${article.elements.slug.value}`,
65+
component: require.resolve(`./src/templates/article-detail.js`),
66+
context: {
67+
codename: article.system.codename,
68+
language: article.preferred_language,
69+
},
70+
})
71+
});
72+
}

examples/relationships/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 0"
1515
},
1616
"dependencies": {
17-
"gatsby": "^4.20.0",
17+
"gatsby": "^5.2.0",
1818
"react": "^18.2.0",
1919
"react-dom": "^18.2.0"
2020
},

examples/resolution/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 0"
1616
},
1717
"dependencies": {
18-
"gatsby": "^4.2.0",
18+
"gatsby": "^5.2.0",
1919
"react": "^18.2.0",
2020
"react-dom": "^18.2.0"
2121
},

examples/resolution/src/pages/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const Index = ({ data }) => (
5353

5454
export const query = graphql`
5555
query AllUrlQuery {
56-
allKontentItemPerson(sort: {order: ASC, fields: elements___name___value}) {
56+
allKontentItemPerson(sort: {elements: {name: {value: ASC}}}) {
5757
nodes {
5858
__typename
5959
elements {
@@ -66,7 +66,7 @@ query AllUrlQuery {
6666
}
6767
}
6868
}
69-
allKontentItemWebsite(sort: {order: ASC, fields: elements___name___value}) {
69+
allKontentItemWebsite(sort: {elements: {name: {value: ASC}}}) {
7070
nodes {
7171
__typename
7272
elements {
@@ -79,7 +79,7 @@ query AllUrlQuery {
7979
}
8080
}
8181
}
82-
allKontentItemRepository(sort: {fields: elements___name___value, order: ASC}) {
82+
allKontentItemRepository(sort: {elements: {name: {value: ASC}}}) {
8383
nodes {
8484
__typename
8585
elements {

0 commit comments

Comments
 (0)