Skip to content

Commit 61f197d

Browse files
authored
chore(gatsby-codemods): Add sort-and-aggr-graphql to README (#36795)
1 parent 98e5b4b commit 61f197d

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

packages/gatsby-codemods/README.md

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A collection of codemod scripts for use with [JSCodeshift](https://github.com/fa
88

99
There are two ways to run codemods on this package.
1010

11-
1. Run via npx
11+
### npx
1212

1313
```shell
1414
npx gatsby-codemods <codemod-name> <filepath>
@@ -18,21 +18,21 @@ npx gatsby-codemods <codemod-name> <filepath>
1818

1919
Note that you cannot pass additional flags to this command. It will automatically run the codemod against file extensions `js, jsx, ts, tsx` and ignore the `node_modules`, `.cache` and `public` directories of your project.
2020

21-
2. Use JSCodeshift directly
21+
### JSCodeshift
2222

23-
- Install JSCodeshift as a global module
23+
1. Install JSCodeshift as a global module
2424

2525
```shell
2626
npm install --global jscodeshift
2727
```
2828

29-
- Install this package
29+
2. Install this package
3030

3131
```shell
3232
npm install gatsby-codemods
3333
```
3434

35-
- Run a transform from this package on your project
35+
3. Run a transform from this package on your project
3636

3737
```shell
3838
jscodeshift -t node_modules/gatsby-codemods/transforms/global-graphql-calls.js my-project
@@ -51,14 +51,37 @@ Structure of a jscodeshift call:
5151

5252
## Included scripts
5353

54+
### `sort-and-aggr-graphql`
55+
56+
Apply changes to the `sort` argument and aggregation's `field` argument as explained in the [RFC: Change to sort and aggregation fields API](https://github.com/gatsbyjs/gatsby/discussions/36242).
57+
58+
See the [Gatsby v4 to v5 migration guide for details on when to use this](https://gatsbyjs.com/docs/migrating-from-v4-to-v5/#graphql-schema-changes-to-sort-and-aggregation-fields).
59+
60+
```shell
61+
npx gatsby-codemods sort-and-aggr-graphql <filepath>
62+
```
63+
64+
Example result:
65+
66+
```diff
67+
{
68+
- allMarkdownRemark(sort: { fields: [frontmatter___date], order: DESC }) {
69+
+ allMarkdownRemark(sort: { frontmatter: { date: DESC } }) {
70+
nodes {
71+
...fields
72+
}
73+
}
74+
}
75+
```
76+
5477
### `global-graphql-calls`
5578

5679
Add a `graphql` import to modules that use the `graphql` tag function without an import. This was supported in Gatsby v1 and deprecated for Gatsby v2.
5780

58-
See the [Gatsby v2 migration guide for details on when to use this](https://gatsbyjs.com/docs/migrating-from-v1-to-v2/#import-graphql-from-gatsby).
81+
See the [Gatsby v1 to v2 migration guide for details on when to use this](https://gatsbyjs.com/docs/migrating-from-v1-to-v2/#import-graphql-from-gatsby).
5982

6083
```shell
61-
jscodeshift -t node_modules/gatsby-codemods/dist/transforms/global-graphql-calls.js <path>
84+
npx gatsby-codemods global-graphql-calls <filepath>
6285
```
6386

6487
Example result:
@@ -86,10 +109,10 @@ export const query = graphql`
86109

87110
Import `Link` from `gatsby` instead of `gatsby-link` and remove the `gatsby-link` import.
88111

89-
See the [Gatsby v2 migration guide for details on when to use this](https://gatsbyjs.com/docs/migrating-from-v1-to-v2/#import-link-from-gatsby).
112+
See the [Gatsby v1 to v2 migration guide for details on when to use this](https://gatsbyjs.com/docs/migrating-from-v1-to-v2/#import-link-from-gatsby).
90113

91114
```shell
92-
jscodeshift -t node_modules/gatsby-codemods/dist/transforms/import-link.js <path>
115+
npx gatsby-codemods import-link <filepath>
93116
```
94117

95118
Example result:
@@ -107,10 +130,10 @@ export default props => (
107130

108131
Change the deprecated `navigateTo` method from `gatsby-link` to `navigate` from the `gatsby` module.
109132

110-
See the [Gatsby v2 migration guide for details on when to use this](https://gatsbyjs.com/docs/migrating-from-v1-to-v2/#change-navigateto-to-navigate).
133+
See the [Gatsby v1 to v2 migration guide for details on when to use this](https://gatsbyjs.com/docs/migrating-from-v1-to-v2/#change-navigateto-to-navigate).
111134

112135
```shell
113-
jscodeshift -t node_modules/gatsby-codemods/dist/transforms/navigate-calls.js <path>
136+
npx gatsby-codemods navigate-calls <filepath>
114137
```
115138

116139
Example result:
@@ -134,10 +157,10 @@ Rename `boundActionCreators` to `actions`. `boundActionCreators` has been deprec
134157

135158
Note: Run this codemod only against files that use `boundActionCreators` instead of running it against a whole directory.
136159

137-
See the [Gatsby v2 migration guide for details on when to use this](https://gatsbyjs.com/docs/migrating-from-v1-to-v2/#rename-boundactioncreators-to-actions).
160+
See the [Gatsby v1 to v2 migration guide for details on when to use this](https://gatsbyjs.com/docs/migrating-from-v1-to-v2/#rename-boundactioncreators-to-actions).
138161

139162
```shell
140-
jscodeshift -t node_modules/gatsby-codemods/dist/transforms/rename-bound-action-creators.js <path-to-file>
163+
npx gatsby-codemods rename-bound-action-creators <filepath>
141164
```
142165

143166
Example result:
@@ -157,9 +180,3 @@ Example result:
157180
}
158181
}
159182
```
160-
161-
## More scripts
162-
163-
Check out [issue 5038 in the Gatsby repo for additional codemod ideas](https://github.com/gatsbyjs/gatsby/issues/5038#issuecomment-411516865).
164-
165-
We'd love your help with writing these!

0 commit comments

Comments
 (0)