Skip to content

Commit 8e381ed

Browse files
authored
feat: migrate to swc plugin instead of babel (#502)
1 parent 295092a commit 8e381ed

7 files changed

Lines changed: 722 additions & 785 deletions

File tree

.babelrc.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

.graphqlrc.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ const config = {
55
generates: {
66
'./src/lib/graphql/': {
77
preset: 'client',
8-
presetConfig: {
9-
fragmentMasking: true,
10-
useTypeImports: true,
11-
},
128
},
139
},
10+
hooks: { afterAllFileWrite: ['prettier --write'] },
1411
}
1512

1613
module.exports = config

next.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,12 @@ module.exports = {
88
images: {
99
domains: ['avatars.githubusercontent.com'],
1010
},
11+
experimental: {
12+
swcPlugins: [
13+
// [
14+
// '@graphql-codegen/client-preset-swc-plugin',
15+
// { artifactDirectory: './src/lib/graphql/', gqlTagName: 'graphql' },
16+
// ],
17+
],
18+
},
1119
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@
3636
},
3737
"devDependencies": {
3838
"@graphql-codegen/cli": "3.3.0",
39-
"@graphql-codegen/client-preset": "2.1.1",
39+
"@graphql-codegen/client-preset-swc-plugin": "0.1.3",
40+
"@graphql-codegen/client-preset": "2.1.0",
4041
"@types/node": "18.15.12",
4142
"@types/react": "18.0.37",
42-
"eslint": "8.38.0",
4343
"eslint-config-next": "13.3.0",
44+
"eslint": "8.38.0",
4445
"husky": "8.0.3",
4546
"prettier": "2.8.7",
4647
"pretty-quick": "3.1.3",

src/lib/graphql/gql.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n fragment ViewerFragment on User {\n name\n image\n }\n':
@@ -25,7 +25,7 @@ const documents = {
2525
*
2626
* @example
2727
* ```ts
28-
* const query = gql(`query GetUser($id: ID!) { user(id: $id) { name } }`);
28+
* const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`);
2929
* ```
3030
*
3131
* The query argument is unknown!

src/lib/graphql/graphql.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ export const ViewerQueryDocument = {
9696
],
9797
},
9898
},
99-
...ViewerFragmentFragmentDoc.definitions,
99+
{
100+
kind: 'FragmentDefinition',
101+
name: { kind: 'Name', value: 'ViewerFragment' },
102+
typeCondition: {
103+
kind: 'NamedType',
104+
name: { kind: 'Name', value: 'User' },
105+
},
106+
selectionSet: {
107+
kind: 'SelectionSet',
108+
selections: [
109+
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
110+
{ kind: 'Field', name: { kind: 'Name', value: 'image' } },
111+
],
112+
},
113+
},
100114
],
101115
} as unknown as DocumentNode<ViewerQueryQuery, ViewerQueryQueryVariables>

yarn.lock

Lines changed: 693 additions & 770 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)