Skip to content

Commit 574242d

Browse files
committed
More babel plugin progress
1 parent 16b4f90 commit 574242d

File tree

8 files changed

+134
-16
lines changed

8 files changed

+134
-16
lines changed

packages/babel-plugin/package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
"version": "0.0.0",
44
"main": "dist/babel-plugin.cjs.js",
55
"module": "dist/babel-plugin.esm.js",
6+
"files": [
7+
"dist",
8+
"!**/*.d.ts"
9+
],
610
"license": "MIT",
711
"dependencies": {
812
"@babel/helper-module-imports": "^7.8.3",
9-
"@babel/runtime": "^7.9.2",
13+
"@babel/runtime": "^7.9.2"
14+
},
15+
"devDependencies": {
1016
"@types/babel__core": "^7.1.7"
1117
},
1218
"repository": "https://github.com/Thinkmill/ts-gql/tree/master/packages/babel-plugin"

packages/next/package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
"module": "dist/next.esm.js",
66
"license": "MIT",
77
"dependencies": {
8-
"@babel/runtime": "^7.9.2"
8+
"@babel/runtime": "^7.9.2",
9+
"@ts-gql/babel-plugin": "^0.0.0"
910
},
1011
"peerDependencies": {
12+
"@ts-gql/compiler": "*",
1113
"graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0"
1214
},
1315
"devDependencies": {
14-
"@ts-gql/compiler": "^0.0.0",
15-
"graphql": "^14.0.0"
16+
"graphql": "^14.0.0",
17+
"@ts-gql/compiler": "^0.0.0"
1618
},
1719
"repository": "https://github.com/Thinkmill/ts-gql/tree/master/packages/next"
1820
}

packages/next/src/index.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,22 @@ export const withTsGql = (internalConfig: any = {}) => (
1111
if (phase === "phase-development-server") {
1212
watch(process.cwd());
1313
}
14-
return typeof internalConfig === "function"
15-
? internalConfig(phase, thing)
16-
: internalConfig;
14+
let internalConfigObj =
15+
typeof internalConfig === "function"
16+
? internalConfig(phase, thing)
17+
: internalConfig;
18+
return {
19+
...internalConfigObj,
20+
webpack(webpackConfig: any, options: any) {
21+
if (!options.defaultLoaders.babel.options.plugins) {
22+
options.defaultLoaders.babel.options.plugins = [];
23+
}
24+
options.defaultLoaders.babel.options.plugins.unshift(
25+
require.resolve("@ts-gql/babel-plugin")
26+
);
27+
return internalConfigObj.webpack
28+
? internalConfigObj.webpack(webpackConfig, options)
29+
: webpackConfig;
30+
},
31+
};
1732
};

pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-app/__generated__/ts-gql/SomeMutationUrql.ts

+98-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-app/babel.config.js

-4
This file was deleted.

test-app/pages/apollo.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ let someMutation = gql`
3535
}
3636
` as import("../__generated__/ts-gql/SomeMutationApollo").type;
3737

38+
console.log({ query, someMutation });
39+
3840
export default () => {
3941
// let client = useApolloClient();
4042
// const { data } = useQuery(query, { variables: { arg: "" } });

test-app/pages/urql.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let query = gql`
2727
let someMutation = gql`
2828
mutation SomeMutationUrql($arg: String!) {
2929
optional(thing: $arg)
30-
ye: somethin
30+
ye: something
3131
}
3232
` as import("../__generated__/ts-gql/SomeMutationUrql").type;
3333

0 commit comments

Comments
 (0)