|
| 1 | +--- |
| 2 | +title: GraphiQL 5 Released; Press F1! |
| 3 | +tags: [announcements, grants] |
| 4 | +date: 2025-07-17 |
| 5 | +byline: Dimitri Postolov |
| 6 | +--- |
| 7 | + |
| 8 | +import { Callout } from "nextra/components" |
| 9 | + |
| 10 | +> The GraphQL Foundation offers [Community Grants](/foundation/community-grant) |
| 11 | +> to help incentivize key technical and community initiatives. As part of the |
| 12 | +> grant, applicants commit to write a blog post report describing their work and |
| 13 | +> its impact on the GraphQL community. The following report was written by grant |
| 14 | +> recipient Dimitri Postolov in June 2025, having completed his project to |
| 15 | +> release Monaco support in GraphiQL. The effort to add Monaco support to |
| 16 | +> GraphiQL was |
| 17 | +> [started over five years ago](https://github.com/graphql/graphiql/issues/1445) |
| 18 | +> and we are beyond excited to see it finally reach fruition! |
| 19 | +
|
| 20 | +<figure className="mt-6"> |
| 21 | + <video autoPlay muted loop playsInline style={{ maxWidth: '100%', borderRadius: '0.5rem' }}> |
| 22 | + <source src="/videos/graphiql5.webm" type="video/webm" /> |
| 23 | + Your browser does not support the video tag. |
| 24 | + </video> |
| 25 | + {/* prettier-ignore */} |
| 26 | + <figcaption className="mt-2 text-center">[GraphiQL 5 with Monaco Editor](https://graphql.org/swapi-graphql/)</figcaption> |
| 27 | +</figure> |
| 28 | + |
| 29 | +This post marks the completion of **8 weeks** of work on my GraphiQL grant, |
| 30 | +sponsored by the **GraphQL Foundation**. |
| 31 | + |
| 32 | +I'm thrilled to announce the release of the all-new **GraphiQL 5**, powered by |
| 33 | +the latest version of the [Monaco editor][monaco-editor]! 🎉 |
| 34 | + |
| 35 | +I also added support for comments in the **Variables** and **Headers** editors. |
| 36 | +This release is a major step forward. |
| 37 | + |
| 38 | +> [The original issue for integrating the Monaco editor](https://github.com/graphql/graphiql/issues/2326) |
| 39 | +> was opened over **3 years ago**.<br/> And the |
| 40 | +> [issue requesting comments support in the Variables editor](https://github.com/graphql/graphiql/issues/780) |
| 41 | +> was opened over **6 years ago**! |
| 42 | +
|
| 43 | +As a primary maintainer of the GraphiQL IDE, I previously led the releases of |
| 44 | +GraphiQL 3 and [GraphiQL 4](/blog/2025-05-31-graphiql-4). This new version marks |
| 45 | +another exciting milestone in the evolution of the project. |
| 46 | + |
| 47 | +## What's New |
| 48 | + |
| 49 | +### Monaco Editor Migration |
| 50 | + |
| 51 | +GraphiQL 5 now uses [Monaco editor][monaco-editor] as default editor, the same |
| 52 | +editor used in [VSCode](https://code.visualstudio.com). |
| 53 | + |
| 54 | +Monaco editor runs heavy language features (like syntax analysis, linting, and |
| 55 | +IntelliSense) in |
| 56 | +[Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers), |
| 57 | +keeping the UI smooth and responsive. |
| 58 | + |
| 59 | +You can now delight your users with identical behavior to Visual Studio Code, |
| 60 | +meaning intelligent autocompletion, hover tooltips, go to definition, find |
| 61 | +references. I've also added |
| 62 | +[`monaco-graphql`](https://github.com/graphql/graphiql/tree/main/packages/monaco-graphql) |
| 63 | +integration in **Query** and **Variables** editor. |
| 64 | + |
| 65 | +<Callout type="info"> |
| 66 | + Clicking on a reference in the Query editor now works by holding `Cmd` on |
| 67 | + macOS or `Ctrl` on Windows/Linux. |
| 68 | +</Callout> |
| 69 | + |
| 70 | +As in VSCode, you can press F1 to see the available commands including features |
| 71 | +such as multiple cursors! |
| 72 | + |
| 73 | +### Support for Comments in Variables and Headers Editors |
| 74 | + |
| 75 | +Thanks to the migration to Monaco Editor, another long-awaited feature has been |
| 76 | +implemented. The **Variables** and **Headers** editors now support comments and |
| 77 | +use the **JSONC** language internally. |
| 78 | + |
| 79 | +In the **Variables** and **Headers** payloads, all comments are automatically |
| 80 | +stripped before the request is executed — the content in the editors **remains |
| 81 | +unchanged**. |
| 82 | + |
| 83 | +### UMD Builds Are Removed |
| 84 | + |
| 85 | +Previously in GraphiQL 4 UMD builds were marked as deprecated, in GraphiQL 5 |
| 86 | +they were removed completely. |
| 87 | + |
| 88 | +We suggest using ESM-based CDNs like [esm.sh][esm.sh] to import GraphiQL in your |
| 89 | +projects. |
| 90 | + |
| 91 | +I updated [GraphiQL CDN example][graphiql-cdn] to show how to use GraphiQL with |
| 92 | +[esm.sh][esm.sh] including how to import and setup workers. |
| 93 | + |
| 94 | +### Examples Update |
| 95 | + |
| 96 | +**GraphiQL with Parcel** and **GraphiQL with Create React App** examples were |
| 97 | +removed. |
| 98 | + |
| 99 | +In addition to updated [GraphiQL CDN example][graphiql-cdn], I've added 2 new |
| 100 | +examples |
| 101 | +[GraphiQL with Vite](https://github.com/graphql/graphiql/tree/main/examples/graphiql-vite) |
| 102 | +and |
| 103 | +[GraphiQL with Next.js and App Router](https://github.com/graphql/graphiql/tree/main/examples/graphiql-nextjs). |
| 104 | + |
| 105 | +### Customizable Default Plugins |
| 106 | + |
| 107 | +GraphiQL 5 lets you take full control over the UI by allowing complete |
| 108 | +customization of its plugins. |
| 109 | + |
| 110 | +#### Removing All Default Plugins |
| 111 | + |
| 112 | +To remove all default plugins (currently **Doc Explorer** and **History**), set |
| 113 | +`referencePlugin={null}` and pass an empty array to the `plugins` prop: |
| 114 | + |
| 115 | +```jsx |
| 116 | +import { GraphiQL } from "graphiql" |
| 117 | + |
| 118 | +const myPlugins = [] |
| 119 | + |
| 120 | +function App() { |
| 121 | + return ( |
| 122 | + <GraphiQL |
| 123 | + referencePlugin={null} // Removes Doc Explorer plugin |
| 124 | + plugins={myPlugins} // Removes History plugin |
| 125 | + /> |
| 126 | + ) |
| 127 | +} |
| 128 | +``` |
| 129 | + |
| 130 | +<Callout type="info"> |
| 131 | + If you're using a custom Doc Explorer, pass it to the `referencePlugin` prop — |
| 132 | + **not** the `plugins` array. It will be automatically included and always |
| 133 | + rendered first. |
| 134 | +</Callout> |
| 135 | + |
| 136 | +#### Adding Plugins While Keeping Defaults |
| 137 | + |
| 138 | +If you're adding custom plugins (e.g. the **Explorer** plugin) and want to keep |
| 139 | +the **History** plugin, you must explicitly include it in the `plugins` array: |
| 140 | + |
| 141 | +```jsx |
| 142 | +import { GraphiQL, HISTORY_PLUGIN } from "graphiql" |
| 143 | +import { explorerPlugin } from "@graphiql/plugin-explorer" |
| 144 | + |
| 145 | +const myPlugins = [HISTORY_PLUGIN, explorerPlugin()] |
| 146 | + |
| 147 | +function App() { |
| 148 | + return <GraphiQL plugins={myPlugins} /> |
| 149 | +} |
| 150 | +``` |
| 151 | + |
| 152 | +### Removed Props |
| 153 | + |
| 154 | +- `readOnly` |
| 155 | +- `keyMap` - to use Vim or Emacs keybindings in Monaco, you can use community |
| 156 | + plugins such as [Monaco Vim](https://github.com/brijeshb42/monaco-vim) or |
| 157 | + [Monaco Emacs](https://github.com/aioutecism/monaco-emacs) |
| 158 | +- `validationRules` - use custom GraphQL worker, see |
| 159 | + [Monaco GraphQL docs](https://github.com/graphql/graphiql/tree/main/packages/monaco-graphql#custom-webworker-for-passing-non-static-config-to-worker) |
| 160 | + |
| 161 | + <figure className="mt-6"> |
| 162 | + {/* prettier-ignore */} |
| 163 | + <></> |
| 164 | + {/* prettier-ignore */} |
| 165 | + <figcaption className="mt-2 text-center">Example of custom GraphQL validation rules</figcaption> |
| 166 | + </figure> |
| 167 | + |
| 168 | +### Additional Changes |
| 169 | + |
| 170 | +The shortcut to focus on the Doc Explorer search input is now `Cmd/Ctrl+Alt+K` |
| 171 | +instead of the previous `Cmd/Ctrl+K`. This was changed because monaco-editor has |
| 172 | +a built-in `Cmd/Ctrl+K` command. |
| 173 | + |
| 174 | +## How to Update |
| 175 | + |
| 176 | +Update `graphiql` using your favorite package manager: |
| 177 | + |
| 178 | +```sh npm2yarn |
| 179 | +npm i graphiql@latest |
| 180 | +``` |
| 181 | + |
| 182 | +### Setup Monaco Workers |
| 183 | + |
| 184 | +You need to set up Monaco workers in your project: |
| 185 | + |
| 186 | +- For **Vite** projects you must import: |
| 187 | + |
| 188 | + ```js |
| 189 | + import "graphiql/setup-workers/vite" |
| 190 | + ``` |
| 191 | + |
| 192 | + <Callout type="info"> |
| 193 | + See [Vite |
| 194 | + example](https://github.com/graphql/graphiql/blob/main/examples/graphiql-vite/src/App.jsx). |
| 195 | + </Callout> |
| 196 | + |
| 197 | +- For Webpack projects such as **Next.js** you must import: |
| 198 | + |
| 199 | + ```js |
| 200 | + import "graphiql/setup-workers/webpack" |
| 201 | + ``` |
| 202 | + |
| 203 | + <Callout type="info"> |
| 204 | + See [Next.js |
| 205 | + example](https://github.com/graphql/graphiql/blob/main/examples/graphiql-nextjs/src/app/page.tsx). |
| 206 | + </Callout> |
| 207 | + |
| 208 | +- For ESM-based CDN usages, you must use |
| 209 | + [`?worker` query](https://esm.sh/#web-worker) to load the module as a web |
| 210 | + worker: |
| 211 | + |
| 212 | + ```js /?worker/ |
| 213 | + import createJSONWorker from "https://esm.sh/monaco-editor/esm/vs/language/json/json.worker.js?worker" |
| 214 | + import createGraphQLWorker from "https://esm.sh/monaco-graphql/esm/graphql.worker.js?worker" |
| 215 | + import createEditorWorker from "https://esm.sh/monaco-editor/esm/vs/editor/editor.worker.js?worker" |
| 216 | + |
| 217 | + globalThis.MonacoEnvironment = { |
| 218 | + getWorker(_workerId, label) { |
| 219 | + switch (label) { |
| 220 | + case "json": |
| 221 | + return createJSONWorker() |
| 222 | + case "graphql": |
| 223 | + return createGraphQLWorker() |
| 224 | + } |
| 225 | + return createEditorWorker() |
| 226 | + } |
| 227 | + } |
| 228 | + ``` |
| 229 | + |
| 230 | + <Callout type="info"> |
| 231 | + See [CDN |
| 232 | + example](https://github.com/graphql/graphiql/blob/main/examples/graphiql-cdn/index.html). |
| 233 | + </Callout> |
| 234 | + |
| 235 | +[monaco-editor]: https://github.com/microsoft/monaco-editor |
| 236 | +[graphiql-cdn]: |
| 237 | + https://github.com/graphql/graphiql/blob/main/examples/graphiql-cdn/index.html |
| 238 | +[esm.sh]: https://esm.sh |
0 commit comments