docs/migration/graphiql-5.0.0.md
graphiql from 4.x to 5.0.0Starting from GraphiQL 5, you need to set up Monaco workers in your project:
For Vite projects you must:
vite-plugin-monaco-editor package:npm install vite-plugin-monaco-editor --save-dev
vite.config.mjs file:// vite.config.mjs
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
+import $monacoEditorPlugin from 'vite-plugin-monaco-editor'
+const monacoEditorPlugin = $monacoEditorPlugin.default ?? $monacoEditorPlugin
export default defineConfig({
plugins: [
react(),
+ monacoEditorPlugin({
+ languageWorkers: ['editorWorkerService', 'json'],
+ customWorkers: [
+ {
+ label: 'graphql',
+ entry: 'monaco-graphql/esm/graphql.worker.js'
+ }
+ ]
+ })
]
})
[!NOTE]
See Vite example.
For Webpack projects such as Next.js you must import:
import 'graphiql/setup-workers/webpack';
[!NOTE]
See Next.js example.
For ESM-based CDN usages, you must use
?worker query to load the module as a web
worker:
import createJSONWorker from 'https://esm.sh/monaco-editor/esm/vs/language/json/json.worker.js?worker';
import createGraphQLWorker from 'https://esm.sh/monaco-graphql/esm/graphql.worker.js?worker';
import createEditorWorker from 'https://esm.sh/monaco-editor/esm/vs/editor/editor.worker.js?worker';
globalThis.MonacoEnvironment = {
getWorker(_workerId, label) {
switch (label) {
case 'json':
return createJSONWorker();
case 'graphql':
return createGraphQLWorker();
}
return createEditorWorker();
},
};
[!NOTE]
See CDN example.
Starting from GraphiQL 5, you can override all default plugins.
To remove all default plugins (currently Doc Explorer and History), set
referencePlugin={null} and pass an empty array to the plugins prop:
import { GraphiQL } from 'graphiql';
const myPlugins = [];
function App() {
return (
<GraphiQL
referencePlugin={null} // Removes Doc Explorer plugin
plugins={myPlugins} // Removes History plugin
/>
);
}
[!NOTE]
If you're using a custom Doc Explorer, pass it to the
referencePluginprop — not thepluginsarray. It will be automatically included and always rendered first.
If you're adding custom plugins (e.g., the Explorer plugin) and want to keep
the History plugin, you must explicitly include it in the plugins array:
import { GraphiQL, HISTORY_PLUGIN } from 'graphiql';
import { explorerPlugin } from '@graphiql/plugin-explorer';
const myPlugins = [HISTORY_PLUGIN, explorerPlugin()];
function App() {
return <GraphiQL plugins={myPlugins} />;
}
graphiql[!WARNING]
⚠️ UMD build is removed. Switch to the ESM CDN example.
codemirror-graphql with monaco-graphqlCmd on macOS or Ctrl on Windows/LinuxqueryvariablesheadersresponsereadOnlykeyMap. To use Vim or Emacs keybindings in Monaco, you can use community plugins. Monaco Vim: https://github.com/brijeshb42/monaco-vim. Monaco Emacs: https://github.com/aioutecism/monaco-emacsvalidationRules. Use custom GraphQL worker, see https://github.com/graphql/graphiql/tree/main/packages/monaco-graphql#custom-webworker-for-passing-non-static-config-to-worker.'[!NOTE]
If you used
query,variablesandheadersin integration tests, you can use the newinitialQuery,initialVariablesandinitialHeadersprops instead. These props will only be used for the first tab. When opening more tabs, the operation editor will start out empty.
initialQueryinitialVariablesinitialHeaderschildren: ReactNode for <GraphiQL.Toolbar /> component@graphiql/react[!IMPORTANT]
Clicking on a reference in the operation editor now works by holding
Cmdon macOS orCtrlon Windows/Linux.
usePrettifyEditors, useCopyQuery, useMergeQuery, useExecutionContext, usePluginContext, useSchemaContext, useStorageContext hooks are deprecated.useGraphiQL and useGraphiQLActions hooks instead. See updated README for more details about them.useSynchronizeValue hookdefaultQuery with empty string does not result in an empty default querydefaultQuery, when is set will only be used for the first tab. When opening more tabs, the operation editor will start out emptyonClickReference from variable editorThe ToolbarMenu component has changed.
The label and className props were removed
The button prop should now be a button element
<ToolbarMenu
label="Options"
button={
<ToolbarButton label="Options">
<SettingsIcon className="graphiql-toolbar-icon" aria-hidden="true" />
</ToolbarButton>
}
>
<ToolbarMenu.Item onSelect={() => console.log('Clicked!')}>
Test
</ToolbarMenu.Item>
</ToolbarMenu>
@graphiql/plugin-code-exporter[!WARNING]
⚠️ UMD build is removed. Switch to the ESM CDN example.
@graphiql/plugin-explorer[!WARNING]
⚠️ UMD build is removed. Switch to the ESM CDN example.
useExplorerContext hook is deprecated. Use new useDocExplorer and useDocExplorerActions hooks instead.Cmd/Ctrl+Alt+K
instead of the previous Cmd/Ctrl+K. This was changed because monaco-editor has
a built-in Cmd/Ctrl+K command.isIntrospecting value, and not based on isFetchinguseHistoryContext hook is deprecated. Use new useHistory and useHistoryActions hooks instead.