Skip to content

Commit 74f5e95

Browse files
authored
Cleanup examples and add notes for JS usage (#84)
* Cleanup examples * Add docs for JavaScript usage
1 parent 787bd0d commit 74f5e95

File tree

9 files changed

+41
-32
lines changed

9 files changed

+41
-32
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ async function main() {
105105
main()
106106
```
107107

108+
### Using vanilla JavaScript instead of TypeScript
109+
110+
GraphClient CLI generates the client artifacts as TypeScript files by default but you can configure CLI to generate JavaScript and JSON files together with additional TypeScript definition files by using `--fileType js` or `--fileType json`.
111+
112+
`js` flag generates all files as JavaScript files with ESM Syntax and `json` flag generates source artifacts as JSON files while entrypoint JavaScript file with old CommonJS syntax because only CommonJS supports JSON files as modules.
113+
114+
Unless you use CommonJS(`require`) specifically, we'd recommend you to use `js` flag.
115+
116+
`graphclient --fileType js`
117+
118+
- [An example for JavaScript usage in CommonJS syntax with JSON files](/examples/javascript-cjs/)
119+
- [An example for JavaScript usage in ESM syntax](/examples/javascript-esm/)
120+
108121
#### The Graph Client DevTools
109122

110123
The Graph Client CLI comes with a built-in GraphiQL so you can experiemnt with queries in real time.

examples/apollo/index.html

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,5 @@
99
<body>
1010
<div id="root"></div>
1111
<script type="module" src="/src/main.tsx"></script>
12-
<script>
13-
setImmediate = (fn) => setTimeout(fn)
14-
process = {
15-
env: {
16-
DEBUG: 1,
17-
},
18-
}
19-
</script>
2012
</body>
2113
</html>

examples/apollo/vite.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ import react from '@vitejs/plugin-react'
44
// https://vitejs.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7+
define: {
8+
process: JSON.stringify({
9+
env: {
10+
DEBUG: 1,
11+
},
12+
}),
13+
},
714
})

examples/execute/index.html

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,5 @@
99
<body>
1010
<div id="root"></div>
1111
<script type="module" src="/src/main.tsx"></script>
12-
<script>
13-
setImmediate = (fn) => setTimeout(fn)
14-
process = {
15-
env: {
16-
DEBUG: 1,
17-
},
18-
}
19-
</script>
2012
</body>
2113
</html>

examples/execute/vite.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ import react from '@vitejs/plugin-react'
44
// https://vitejs.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7+
define: {
8+
process: JSON.stringify({
9+
env: {
10+
DEBUG: 1,
11+
},
12+
}),
13+
},
714
})

examples/react-query/index.html

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,5 @@
99
<body>
1010
<div id="root"></div>
1111
<script type="module" src="/src/main.tsx"></script>
12-
<script>
13-
setImmediate = (fn) => setTimeout(fn)
14-
process = {
15-
env: {
16-
DEBUG: 1,
17-
},
18-
}
19-
</script>
2012
</body>
2113
</html>

examples/react-query/vite.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ import react from '@vitejs/plugin-react'
44
// https://vitejs.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7+
define: {
8+
process: JSON.stringify({
9+
env: {
10+
DEBUG: 1,
11+
},
12+
}),
13+
},
714
})

examples/urql/index.html

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,5 @@
99
<body>
1010
<div id="root"></div>
1111
<script type="module" src="/src/main.tsx"></script>
12-
<script>
13-
setImmediate = (fn) => setTimeout(fn)
14-
process = {
15-
env: {
16-
DEBUG: 1,
17-
},
18-
}
19-
</script>
2012
</body>
2113
</html>

examples/urql/vite.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ import react from '@vitejs/plugin-react'
44
// https://vitejs.dev/config/
55
export default defineConfig({
66
plugins: [react()],
7+
define: {
8+
process: JSON.stringify({
9+
env: {
10+
DEBUG: 1,
11+
},
12+
}),
13+
},
714
})

0 commit comments

Comments
 (0)