Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTF-next: codemods to help for migration #35113

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4d0cf1c
WIP - first codemods for graphql changes
axe312ger Mar 11, 2022
4261d0c
feat: add name subfield for new contentType sys field
axe312ger Mar 16, 2022
1711335
tell user about manual required changes and transform some content ty…
axe312ger Mar 16, 2022
eff139a
feat: flatten asset filters
axe312ger Mar 16, 2022
0a0b8d6
fix: all Contentful content type selectors within a query will now re…
axe312ger Mar 16, 2022
eb32056
feat: apply changes to sys structure to js and improve sys.type edge-…
axe312ger Mar 16, 2022
5fd7084
fix: take useNameForId into account when creating reference fields
axe312ger Aug 15, 2023
ed1c68a
fix: rename metadata field to contentfulMetadata
axe312ger Aug 15, 2023
a40f3fc
fix: add linkedFrom field to restricted/reserved field names
axe312ger Aug 15, 2023
4e6e0d7
fix: use same list of restricted node fields everywhere
axe312ger Aug 15, 2023
339ffb7
refactor: cleanup codemods
axe312ger Aug 24, 2023
133482a
fix: avoid endless loop when transforming spaceId for sys
axe312ger Aug 24, 2023
e2769b6
fix: avoid endless loop when transforming spaceId for sys
axe312ger Aug 24, 2023
0dc62c0
feat: basic support for fragments
axe312ger Aug 24, 2023
7633075
test: initial fixtures for most yet implemented codemods
axe312ger Aug 24, 2023
2f22015
test: ensure fragments also support asset flattening
axe312ger Aug 24, 2023
a41e595
test: extend codemod test for fragments
axe312ger Aug 24, 2023
208482a
feat: support inline fragments as well
axe312ger Aug 24, 2023
5c74473
feat: support flattening of single target contentful asset queries
axe312ger Aug 24, 2023
63d8e55
feat: transform sys fields in single entity and collection queries
axe312ger Aug 25, 2023
9d2531a
feat: add more tests and almost working asset object transform
axe312ger Aug 29, 2023
a1ebbdc
feat: properly merge existing fields in sys and fix contentType trans…
axe312ger Aug 29, 2023
5501ef4
feat: add support for tags and rename metadata to contentfulMetadata
axe312ger Aug 29, 2023
e113ba0
feat: support new sys and asset structures when sorting
axe312ger Aug 29, 2023
59d06c7
feat: warn when using schema customizations or identifiers that match…
axe312ger Aug 29, 2023
f04b2f8
feat: properly restructure object destructure code with new sys struc…
axe312ger Aug 29, 2023
6bd837d
feat: flatten asset structure in js object selectors
axe312ger Aug 29, 2023
b081063
feat: rename content type names within custom resolvers defined in a …
axe312ger Aug 31, 2023
0542d39
chore: cleanup
axe312ger Aug 31, 2023
14454be
Merge branch 'feat/contentful-schema-generation' into feat/contentful…
axe312ger Aug 31, 2023
009b261
Merge branch 'feat/contentful-schema-generation' into feat/contentful…
axe312ger Aug 31, 2023
d736e0c
Merge branch 'feat/contentful-schema-generation' into feat/contentful…
axe312ger Aug 31, 2023
51916d4
Merge branch 'feat/contentful-schema-generation' into feat/contentful…
axe312ger Sep 4, 2023
91db5ae
Merge branch 'feat/contentful-schema-generation' into feat/contentful…
axe312ger Sep 4, 2023
3479798
feat: support typescript interfaces and improve content type selector…
axe312ger Sep 5, 2023
3141aab
fix: make codemods more reliable
axe312ger Sep 5, 2023
855ec7c
chore: format using-contentful
axe312ger Sep 5, 2023
e8a1b17
refactor: migrate using-contentful example code via codemods
axe312ger Sep 5, 2023
c8bb851
WIP - manual migrations
axe312ger Sep 5, 2023
b0b216d
Merge branch 'feat/contentful-schema-generation' into feat/contentful…
axe312ger Sep 14, 2023
fd0c41d
Merge branch 'feat/contentful-schema-generation' into feat/contentful…
axe312ger Sep 14, 2023
cd72e73
build: fix versions in using-contentful example
axe312ger Sep 14, 2023
319cea0
Merge branch 'feat/contentful-schema-generation' into feat/contentful…
axe312ger Sep 14, 2023
037a581
build: update yarn.lock
axe312ger Sep 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions examples/using-contentful/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"version": "1.0.0",
"author": "Marcus Ericsson <[email protected]> (mericsson.com)",
"dependencies": {
"gatsby": "next",
"gatsby-core-utils": "next",
"gatsby-plugin-image": "next",
"gatsby-plugin-sharp": "next",
"gatsby-plugin-typography": "next",
"gatsby-source-contentful": "next",
"gatsby-transformer-remark": "next",
"gatsby": "^5.13.0-next.1",
"gatsby-core-utils": "^4.13.0-next.0",
"gatsby-plugin-image": "^3.13.0-next.0",
"gatsby-plugin-sharp": "^5.13.0-next.0",
"gatsby-plugin-typography": "^5.13.0-next.0",
"gatsby-source-contentful": "^8.13.0-next.1",
"gatsby-transformer-remark": "^6.13.0-next.0",
"prop-types": "^15.7.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -24,9 +24,6 @@
],
"license": "MIT",
"main": "n/a",
"resolutions": {
"contentful": "6.1.3"
},
"scripts": {
"develop": "gatsby develop",
"build": "gatsby build",
Expand Down
2 changes: 1 addition & 1 deletion examples/using-contentful/src/layouts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const DefaultLayout = ({ children }) => (
<>
<header
style={{
textAlign: "center",
textAlign: `center`,
backgroundColor: `tomato`,
padding: rhythm(1 / 2),
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ const propTypes = {

class CategoryTemplate extends React.Component {
render() {
const category = this.props.data.contentfulCategory
const category = this.props.data.contentfulContentTypeCategory
const {
title: { title },
product,
title: { raw: title },
linkedFrom: { ContentfulContentTypeProduct },
icon,
} = category
const iconImg = icon.gatsbyImageData
Expand All @@ -42,10 +42,10 @@ class CategoryTemplate extends React.Component {
<div>
<h2>Products</h2>
<ul>
{product &&
product.map((p, i) => (
{ContentfulContentTypeProduct.length &&
ContentfulContentTypeProduct.map((p, i) => (
<li key={i}>
<Link to={p.gatsbyPath}>{p.productName.productName}</Link>
<Link to={p.gatsbyPath}>{p.productName.raw}</Link>
</li>
))}
</ul>
Expand All @@ -60,19 +60,21 @@ CategoryTemplate.propTypes = propTypes
export default CategoryTemplate

export const pageQuery = graphql`
query($id: String!) {
contentfulCategory(id: { eq: $id }) {
query ($id: String!) {
contentfulContentTypeCategory(id: { eq: $id }) {
title {
title
raw
}
icon {
gatsbyImageData(layout: FIXED, width: 75)
}
product {
gatsbyPath(filePath: "/products/{ContentfulProduct.id}")
id
productName {
productName
linkedFrom {
ContentfulContentTypeProduct {
gatsbyPath(filePath: "/products/{ContentfulContentTypeProduct.id}")
id
productName {
raw
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/using-contentful/src/pages/image-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ const ImageAPI = props => {
export default ImageAPI

export const pageQuery = graphql`
query {
allContentfulAsset(filter: { node_locale: { eq: "en-US" } }) {
{
allContentfulAsset(filter: { sys: { locale: { eq: "en-US" } } }) {
edges {
node {
title
Expand Down
18 changes: 11 additions & 7 deletions examples/using-contentful/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,32 @@ IndexPage.propTypes = propTypes
export default IndexPage

export const pageQuery = graphql`
query {
us: allContentfulProduct(filter: { node_locale: { eq: "en-US" } }) {
{
us: allContentfulContentTypeProduct(
filter: { sys: { locale: { eq: "en-US" } } }
) {
edges {
node {
id
gatsbyPath(filePath: "/products/{ContentfulProduct.id}")
gatsbyPath(filePath: "/products/{ContentfulContentTypeProduct.id}")
productName {
productName
raw
}
image {
gatsbyImageData(layout: FIXED, width: 75)
}
}
}
}
german: allContentfulProduct(filter: { node_locale: { eq: "de" } }) {
german: allContentfulContentTypeProduct(
filter: { sys: { locale: { eq: "de" } } }
) {
edges {
node {
id
gatsbyPath(filePath: "/products/{ContentfulProduct.id}")
gatsbyPath(filePath: "/products/{ContentfulContentTypeProduct.id}")
productName {
productName
raw
}
image {
gatsbyImageData(layout: FIXED, width: 75)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const propTypes = {

class ProductTemplate extends React.Component {
render() {
const product = this.props.data.contentfulProduct
const product = this.props.data.contentfulContentTypeProduct
const {
productName: { productName },
productName: { raw: productName },
productDescription,
price,
image,
Expand All @@ -39,7 +39,7 @@ class ProductTemplate extends React.Component {
)}
</div>
<h1 style={{ marginBottom: rhythm(1 / 2) }}>{productName}</h1>
<h4>Made by {brand.companyName.companyName}</h4>
<h4>Made by {brand.companyName.raw}</h4>
<div>
<span>Price: ${price}</span>
<div
Expand All @@ -53,7 +53,7 @@ class ProductTemplate extends React.Component {
{categories.map((category, i) => (
<li key={i}>
<Link key={i} to={category.gatsbyPath}>
{category.title.title}
{category.title.raw}
</Link>
</li>
))}
Expand All @@ -70,10 +70,10 @@ ProductTemplate.propTypes = propTypes
export default ProductTemplate

export const pageQuery = graphql`
query($id: String!) {
contentfulProduct(id: { eq: $id }) {
query ($id: String!) {
contentfulContentTypeProduct(id: { eq: $id }) {
productName {
productName
raw
}
productDescription {
childMarkdownRemark {
Expand All @@ -86,14 +86,14 @@ export const pageQuery = graphql`
}
brand {
companyName {
companyName
raw
}
}
categories {
id
gatsbyPath(filePath: "/categories/{ContentfulCategory.id}")
gatsbyPath(filePath: "/categories/{ContentfulContentTypeCategory.id}")
title {
title
raw
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@
"watch": "lerna run watch --no-sort --stream --concurrency 999"
},
"workspaces": [
"packages/*"
"packages/*",
"examples/using-contentful"
],
"resolutions": {
"@babel/plugin-transform-modules-commonjs": "7.18.6"
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-codemods/src/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from "path"
import execa from "execa"

const codemods = [
`gatsby-source-contentful`,
`gatsby-plugin-image`,
`global-graphql-calls`,
`import-link`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Data {
allContentfulTemplatePage: FooConnection
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Data {
allContentfulContentTypeTemplatePage: FooConnection
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const demo = [
...data.allContentfulFoo.nodes,
...data.allContentfulBar.nodes,
]
const content = data.contentfulPage.content
const {
data: {
allContentfulTemplatePage: { nodes: templatePages },
},
} = await graphql(``)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const demo = [
...data.allContentfulContentTypeFoo.nodes,
...data.allContentfulContentTypeBar.nodes,
]
const content = data.contentfulContentTypePage.content
const {
data: {
allContentfulContentTypeTemplatePage: { nodes: templatePages },
},
} = await graphql(``)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react"

export default () => (
<img
src={`${someQueryResultData.logo.file.url}?w=${someQueryResultData.logo.file.details.image.width}&q=40&fm=jpg`}
/>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react"

export default () => (
<img
src={`${someQueryResultData.logo.url}?w=${someQueryResultData.logo.width}&q=40&fm=jpg`}
/>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const res1 = allContentfulPage.nodes.contentful_id
const res2 = allContentfulPage.nodes.sys.contentType.__typename
const { contentful_id, createdAt, updatedAt } = allContentfulPage.nodes
const { title, metaDescription, metaImage, content } = data.contentfulPage
const { foo } = result.data.allContentfulPage.nodes[0]
const {
revision,
sys: {
contentType: { __typename },
},
} = allContentfulPage.nodes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const res1 = allContentfulPage.nodes.sys.id
const res2 = allContentfulPage.nodes.sys.contentType.name
const {
sys: {
id: contentful_id,
firstPublishedAt: createdAt,
publishedAt: updatedAt
}
} = allContentfulPage.nodes
const { title, metaDescription, metaImage, content } = data.contentfulContentTypePage
const { foo } = result.data.allContentfulContentTypePage.nodes[0]
const {
sys: {
publishedVersion: revision,
contentType: { name }
}
} = allContentfulPage.nodes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exports.createSchemaCustomization = null
export const createSchemaCustomization = null

// export function createResolvers(actions) {
// actions.createResolvers({
// ContentfulFoo: {},
// })
// }

export const createResolvers = (actions) => {
actions.createResolvers({
ContentfulFoo: {},
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exports.createSchemaCustomization = null
export const createSchemaCustomization = null

// export function createResolvers(actions) {
// actions.createResolvers({
// ContentfulFoo: {},
// })
// }

export const createResolvers = (actions) => {
actions.createResolvers({
ContentfulContentTypeFoo: {},
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const result = await graphql`
{
allContentfulPage(limit: 1000) {
nodes {
id
}
}
}
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const result = await graphql`{
allContentfulContentTypePage(limit: 1000) {
nodes {
id
}
}
}`
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export const ExampleFragment = graphql`
fragment Example on ContentfulExample {
title
contentful_id
logo {
file {
url
fileName
contentType
details {
size
image {
width
height
}
}
}
}
}
{
allContentfulFoo {
nodes {
... on ContentfulExample {
contentful_id
logo {
file {
url
}
}
}
}
}
}
`
Loading