Skip to content

Commit 5af14f6

Browse files
authored
fix graphiql 5 with vite example (#4042)
* fix graphiql 5 with vite example * upd * upd
1 parent c392ee0 commit 5af14f6

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

docs/migration/graphiql-5.0.0.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,38 @@
22

33
Starting from GraphiQL 5, you need to set up Monaco workers in your project:
44

5-
- For **Vite** projects you must import:
5+
- For **Vite** projects you must:
66

7-
```js
8-
import 'graphiql/setup-workers/vite';
7+
1. Install `vite-plugin-monaco-editor` package:
8+
9+
```sh
10+
npm install vite-plugin-monaco-editor --save-dev
11+
```
12+
13+
2. Import and configure the plugin in your `vite.config.mjs` file:
14+
15+
```diff
16+
// vite.config.mjs
17+
import { defineConfig } from 'vite'
18+
import react from '@vitejs/plugin-react'
19+
+import $monacoEditorPlugin from 'vite-plugin-monaco-editor'
20+
21+
+const monacoEditorPlugin = $monacoEditorPlugin.default ?? $monacoEditorPlugin
22+
23+
export default defineConfig({
24+
plugins: [
25+
react(),
26+
+ monacoEditorPlugin({
27+
+ languageWorkers: ['editorWorkerService', 'json'],
28+
+ customWorkers: [
29+
+ {
30+
+ label: 'graphql',
31+
+ entry: 'monaco-graphql/esm/graphql.worker.js'
32+
+ }
33+
+ ]
34+
+ })
35+
]
36+
})
937
```
1038

1139
> [!NOTE]

examples/graphiql-vite/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
},
1111
"devDependencies": {
1212
"@vitejs/plugin-react": "^4.4.1",
13-
"vite": "^6.3.4"
13+
"vite": "^6.3.4",
14+
"vite-plugin-monaco-editor": "^1.1.0"
1415
},
1516
"scripts": {
1617
"dev": "vite",

examples/graphiql-vite/src/App.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { GraphiQL } from 'graphiql';
2-
import 'graphiql/setup-workers/vite';
32
import 'graphiql/style.css';
43

54
async function fetcher(graphQLParams) {
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
import { defineConfig } from 'vite';
22
import react from '@vitejs/plugin-react';
3+
import $monacoEditorPlugin from 'vite-plugin-monaco-editor';
4+
5+
const monacoEditorPlugin = $monacoEditorPlugin.default ?? $monacoEditorPlugin;
36

47
export default defineConfig({
5-
plugins: [react()],
6-
worker: {
7-
format: 'es',
8-
},
8+
plugins: [
9+
react(),
10+
monacoEditorPlugin({
11+
languageWorkers: ['editorWorkerService', 'json'],
12+
customWorkers: [
13+
{
14+
label: 'graphql',
15+
entry: 'monaco-graphql/esm/graphql.worker.js',
16+
},
17+
],
18+
}),
19+
],
920
});

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12611,6 +12611,7 @@ __metadata:
1261112611
react: "npm:^19.1.0"
1261212612
react-dom: "npm:^19.1.0"
1261312613
vite: "npm:^6.3.4"
12614+
vite-plugin-monaco-editor: "npm:^1.1.0"
1261412615
languageName: unknown
1261512616
linkType: soft
1261612617

@@ -24790,6 +24791,15 @@ __metadata:
2479024791
languageName: node
2479124792
linkType: hard
2479224793

24794+
"vite-plugin-monaco-editor@npm:^1.1.0":
24795+
version: 1.1.0
24796+
resolution: "vite-plugin-monaco-editor@npm:1.1.0"
24797+
peerDependencies:
24798+
monaco-editor: ">=0.33.0"
24799+
checksum: 10c0/1f0d839c194d79f21f4ef192d19d82e42ed6dbbab580df684db2e4eeb01d1f2e9c572e9e5b50e9887e9028a54514c496ee6db9d68cab579d375d09456d8b91ee
24800+
languageName: node
24801+
linkType: hard
24802+
2479324803
"vite-plugin-svgr@npm:^4.3.0":
2479424804
version: 4.3.0
2479524805
resolution: "vite-plugin-svgr@npm:4.3.0"

0 commit comments

Comments
 (0)