Skip to content

graphiql 5: Remove query, variables, headers and response props from <GraphiQL /> #3735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 141 commits into from
Jun 21, 2025
Merged
Show file tree
Hide file tree
Changes from 138 commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
fec285b
changeset pre enter alpha
dimaMachina Aug 7, 2024
3c1a345
[graphiql-react/graphiql] new looks of tabs (#3644)
dimaMachina Aug 7, 2024
5d90e0e
[2] GraphiQL x Vite v5 (#3679)
dimaMachina Aug 7, 2024
11aacd0
[3] remove unused webpack deps (#3681)
dimaMachina Aug 7, 2024
955573a
Merge branch 'main' into graphiql-v4
dimaMachina Aug 7, 2024
8efb873
[4] update graphql to `16.9.0` and use vite `define` configuration to…
dimaMachina Aug 7, 2024
0fdd9b9
remove `data-testid="graphiql-container"` (#3688)
dimaMachina Aug 7, 2024
c5b3aa2
commit `pre.json` until `graphiql-v4` will be added to list of author…
dimaMachina Aug 7, 2024
61fc27a
remove `graphiql-v4` from release.yml
dimaMachina Aug 7, 2024
09e7004
[v4] remove `disableTabs` option (#3687)
dimaMachina Aug 7, 2024
11bacb8
commit `pre.json`
dimaMachina Aug 7, 2024
445bf02
add `graphiql-v4` in release.yml
dimaMachina Aug 7, 2024
d34246e
Merge branch 'main' into graphiql-v4
dimaMachina Aug 7, 2024
82bc961
[v4] prefer `location` over `window.location` and prefer `navigator` …
dimaMachina Aug 7, 2024
93453fc
[v4] remove `build.sh` and `checkgit.sh` (#3694)
dimaMachina Aug 7, 2024
2005871
[v4] test umd build only on ci, locally test cdn.ts (#3693)
dimaMachina Aug 7, 2024
bf3ea52
[v4] convert graphiql e2e server to ESM (#3697)
dimaMachina Aug 8, 2024
bb70347
Merge branch 'main' into graphiql-v4
dimaMachina Aug 8, 2024
5e43d2b
[v4] update changeset for changed exports (#3700)
dimaMachina Aug 8, 2024
95668f5
Merge branch 'main' into graphiql-v4
dimaMachina Aug 8, 2024
00415d2
[v4] generate types with `vite-plugin-dts` (#3702)
dimaMachina Aug 9, 2024
8ff87d7
[v4] use `vite build --watch` instead of `vite` for `dev` script beca…
dimaMachina Aug 9, 2024
343dd59
[v4] remove graphiql default export (#3706)
dimaMachina Aug 9, 2024
4e26b74
Merge branch 'main' into graphiql-v4
dimaMachina Aug 9, 2024
db181b2
[v4] fix netlify deploy (#3708)
dimaMachina Aug 9, 2024
9baf1f0
change `style.css` imports (#3709)
dimaMachina Aug 9, 2024
7afb4be
Update poor-ghosts-jump.md
dimaMachina Aug 9, 2024
1a6d63d
Version Packages (alpha) (#3689)
acao Aug 11, 2024
27bbc51
[v4] show tabs even there is only 1 tab (#3713)
dimaMachina Aug 13, 2024
3c901c1
[v4] Remove `toolbar.additionalContent` and `toolbar.additionalCompon…
dimaMachina Aug 13, 2024
cb4553d
Version Packages (alpha) (#3714)
acao Aug 13, 2024
cc2808f
[v4] use `position: absolute` for `.graphiql-logo` class (#3716)
dimaMachina Aug 13, 2024
bf0c4e7
[v4] remove `createComponentGroup` utility in favour `Object.assign` …
dimaMachina Aug 13, 2024
15fff26
Version Packages (alpha) (#3718)
acao Aug 13, 2024
d3fc470
[v4] fix merge conflicts with `main` (#3719)
dimaMachina Aug 13, 2024
b468046
Merge branch 'main' into graphiql-v4
dimaMachina Aug 14, 2024
79f3abf
[v4] fix scrollbar appearing in sidebar (#3720)
dimaMachina Aug 14, 2024
9d28035
Version Packages (alpha) (#3723)
acao Aug 14, 2024
4609e00
Merge branch 'main' into graphiql-v4
dimaMachina Aug 14, 2024
6587675
Merge branch 'main' into graphiql-v4
dimaMachina Aug 14, 2024
f2a6b39
Merge branch 'main' into graphiql-v4
dimaMachina Aug 14, 2024
f8b719f
style: Don't convert single \n to <br> (#3414)
leonardehrenfried Aug 14, 2024
196e9a0
[v4] some refactoring (#3726)
dimaMachina Aug 14, 2024
3bcbda4
Merge branch 'main' into graphiql-v4
dimaMachina Aug 14, 2024
a1a5208
[v4] polish `tabs.cy` tests, remove `.graphiql-session` class (#3728)
dimaMachina Aug 14, 2024
99c64ac
Merge branch 'main' into graphiql-v4
dimaMachina Aug 15, 2024
167629f
fix tests
dimaMachina Aug 15, 2024
360a038
[v4] rollback `position: absolute` style for `.graphiql-logo` because…
dimaMachina Aug 15, 2024
8d9d469
Merge branch 'main' into graphiql-v4
dimaMachina Aug 15, 2024
fd0e25f
Version Packages (alpha) (#3725)
acao Aug 15, 2024
058d1d8
Merge branch 'main' into graphiql-v4
dimaMachina Aug 15, 2024
c966fa1
Merge branch 'main' into graphiql-v4
dimaMachina Aug 15, 2024
8dbddb5
Add support for onPrettifyQuery callback to enable customised query f…
dimaMachina Aug 15, 2024
e10e96c
Merge branch 'main' into graphiql-v4
dimaMachina Aug 15, 2024
3a2580e
Version Packages (alpha) (#3732)
acao Aug 15, 2024
053db6c
aa
dimaMachina Aug 15, 2024
47874bf
aa
dimaMachina Aug 15, 2024
d2daab6
Apply suggestions from code review
dimaMachina Aug 16, 2024
0cebb37
Merge branch 'graphiql-5' into remove-controlled-props
dimaMachina Jun 15, 2025
28caa5f
upd
dimaMachina Jun 15, 2025
e5ce244
upd
dimaMachina Jun 15, 2025
4814361
Delete .changeset/breezy-chicken-crash.md
dimaMachina Jun 15, 2025
b2f6e08
Delete .changeset/add-on-prettify-callback.md
dimaMachina Jun 15, 2025
4b07a3a
Delete .changeset/few-steaks-clap.md
dimaMachina Jun 15, 2025
10c2a87
Delete .changeset/flat-lies-heal.md
dimaMachina Jun 15, 2025
8d263b9
Delete .changeset/gentle-bugs-mix.md
dimaMachina Jun 15, 2025
6bb8d39
Delete .changeset/green-pugs-worry.md
dimaMachina Jun 15, 2025
eb240d4
Delete .changeset/good-vans-refuse.md
dimaMachina Jun 15, 2025
a68ddfe
Delete .changeset/metal-glasses-bow.md
dimaMachina Jun 15, 2025
45ffb18
Delete .changeset/hungry-spiders-cheat.md
dimaMachina Jun 15, 2025
aaf4255
Delete .changeset/old-zebras-knock.md
dimaMachina Jun 15, 2025
a123911
Delete .changeset/orange-rivers-draw.md
dimaMachina Jun 15, 2025
22aa205
Delete .changeset/olive-mice-hide.md
dimaMachina Jun 15, 2025
baa5d0f
Delete .changeset/pink-moose-shake.md
dimaMachina Jun 15, 2025
e93d129
Delete .changeset/poor-ghosts-jump.md
dimaMachina Jun 15, 2025
cffdcb7
Delete .changeset/red-papayas-fly.md
dimaMachina Jun 15, 2025
76acce0
Delete .changeset/rich-jobs-kick.md
dimaMachina Jun 15, 2025
bb89fa9
Delete .changeset/serious-forks-sip.md
dimaMachina Jun 15, 2025
f1813ac
Delete .changeset/strong-ears-bake.md
dimaMachina Jun 15, 2025
b7adb42
Delete .changeset/spotty-bulldogs-confess.md
dimaMachina Jun 15, 2025
80c204f
Delete .changeset/thick-adults-leave.md
dimaMachina Jun 15, 2025
1424b48
Delete .changeset/weak-dancers-jog.md
dimaMachina Jun 15, 2025
a80135d
Delete .changeset/wicked-seas-laugh.md
dimaMachina Jun 15, 2025
fa041aa
Delete .changeset/thirty-spoons-call.md
dimaMachina Jun 15, 2025
553a455
Update .changeset/nasty-cows-train.md
dimaMachina Jun 15, 2025
291c415
Update resources/custom-words.txt
dimaMachina Jun 15, 2025
a96bc2f
rollback
dimaMachina Jun 15, 2025
6c44e39
rollback
dimaMachina Jun 15, 2025
7659557
rollback
dimaMachina Jun 15, 2025
a945daf
upd
dimaMachina Jun 15, 2025
d4caaa3
upd
dimaMachina Jun 15, 2025
161dd5c
upd
dimaMachina Jun 15, 2025
20a9fdd
upd
dimaMachina Jun 15, 2025
a225600
upd
dimaMachina Jun 15, 2025
77721c7
upd
dimaMachina Jun 15, 2025
d1ef47c
upd
dimaMachina Jun 15, 2025
eeefee7
prettier
dimaMachina Jun 15, 2025
da295d5
upd
dimaMachina Jun 15, 2025
d3e1b67
upd
dimaMachina Jun 15, 2025
0ba00ad
upd
dimaMachina Jun 15, 2025
f928178
upd
dimaMachina Jun 15, 2025
1cf8c37
upd
dimaMachina Jun 15, 2025
6b82183
upd
dimaMachina Jun 15, 2025
96901c1
upd
dimaMachina Jun 15, 2025
772a03a
upd
dimaMachina Jun 15, 2025
6ebee47
try isMounted
dimaMachina Jun 15, 2025
2882a7d
Update packages/graphiql/cypress/e2e/headers.cy.ts
dimaMachina Jun 15, 2025
c34a281
Update packages/graphiql/src/e2e.ts
dimaMachina Jun 15, 2025
4bb6fd6
fix tabs tests
dimaMachina Jun 15, 2025
3c3a9d1
try
dimaMachina Jun 15, 2025
773cbc6
improve use did update
dimaMachina Jun 15, 2025
68824ea
Merge branch 'graphiql-5' into remove-controlled-props
dimaMachina Jun 15, 2025
11fd479
upd
dimaMachina Jun 15, 2025
5f591e7
upd changeset
dimaMachina Jun 16, 2025
1e66006
upd
dimaMachina Jun 16, 2025
e821d2d
upd
dimaMachina Jun 16, 2025
3889e6c
upd
dimaMachina Jun 16, 2025
40b748a
upd
dimaMachina Jun 16, 2025
d50f84f
upd
dimaMachina Jun 16, 2025
52356c6
upd
dimaMachina Jun 16, 2025
4e507b3
upd
dimaMachina Jun 16, 2025
6528684
upd
dimaMachina Jun 16, 2025
5c3677f
upd
dimaMachina Jun 16, 2025
762cad2
upd
dimaMachina Jun 16, 2025
1ab533a
upd
dimaMachina Jun 16, 2025
8f0ce0e
upd
dimaMachina Jun 16, 2025
4f0408d
upd
dimaMachina Jun 16, 2025
c2a78fd
upd
dimaMachina Jun 16, 2025
6d304bb
upd
dimaMachina Jun 16, 2025
42955d1
upd
dimaMachina Jun 16, 2025
2f45ef8
upd
dimaMachina Jun 16, 2025
2db9489
upd
dimaMachina Jun 17, 2025
04a9495
upd
dimaMachina Jun 17, 2025
f95e867
upd
dimaMachina Jun 17, 2025
0460780
upd
dimaMachina Jun 17, 2025
f73e478
Merge branch 'graphiql-5' into remove-controlled-props
dimaMachina Jun 21, 2025
bbfeaa6
upd
dimaMachina Jun 21, 2025
9e63b43
upd error message and changeset
dimaMachina Jun 21, 2025
060732e
Update packages/graphiql/src/GraphiQL.spec.tsx
dimaMachina Jun 21, 2025
08b9f82
Update packages/graphiql/src/GraphiQL.spec.tsx
dimaMachina Jun 21, 2025
d3c6cfd
improve tsdoc comment
dimaMachina Jun 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/nasty-cows-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@graphiql/react': minor
'graphiql': major
---

- Remove `query`, `variables`, `headers`, and `response` props from `<GraphiQL />` and `<GraphiQLProvider />`
- Add `initialQuery`, `initialVariables` and `initialHeaders` props
- Fix `defaultQuery`, when is set will only be used for the first tab. When opening more tabs, the query editor will start out empty
- remove `useSynchronizeValue` hook
1 change: 0 additions & 1 deletion packages/graphiql-react/src/components/header-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const HeaderEditor: FC<HeaderEditorProps> = ({ onEdit, ...props }) => {
);
useEffect(() => {
const model = getOrCreateModel({ uri: HEADER_URI, value: initialHeaders });
// Build the editor
const editor = createEditor(ref, { model });
setEditor({ headerEditor: editor });
const disposables = [
Expand Down
103 changes: 60 additions & 43 deletions packages/graphiql-react/src/components/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
/* eslint sort-keys: "error" */
import type {
ComponentPropsWithoutRef,
FC,
ReactElement,
ReactNode,
RefObject,
} from 'react';
import type { ComponentPropsWithoutRef, FC, ReactNode, RefObject } from 'react';
import { createContext, useContext, useRef, useEffect } from 'react';
import { create, useStore, UseBoundStore, StoreApi } from 'zustand';
import { useShallow } from 'zustand/shallow';
Expand All @@ -22,7 +16,7 @@ import {
import { StorageStore, useStorage } from '../stores/storage';
import { ThemeStore } from '../stores/theme';
import type { SlicesWithActions } from '../types';
import { pick, useDidUpdate, useSynchronizeValue } from '../utility';
import { useDidUpdate } from '../utility';
import {
FragmentDefinitionNode,
parse,
Expand Down Expand Up @@ -69,8 +63,56 @@ export const GraphiQLProvider: FC<GraphiQLProviderProps> = ({
}
// @ts-expect-error -- runtime check
if (props.validationRules) {
throw new Error(
'`validationRules` prop is removed. Use custom GraphQL worker, see https://github.com/graphql/graphiql/tree/main/packages/monaco-graphql#custom-webworker-for-passing-non-static-config-to-worker.',
throw new TypeError(
'The `validationRules` prop has been removed. Use custom GraphQL worker, see https://github.com/graphql/graphiql/tree/main/packages/monaco-graphql#custom-webworker-for-passing-non-static-config-to-worker.',
);
}
// @ts-expect-error -- runtime check
if (props.query) {
throw new TypeError(
'The `query` prop has been removed. Use `initialQuery` prop instead, or set value programmatically using:\n' +
`
const queryEditor = useGraphiQL(state => state.queryEditor)

useEffect(() => {
queryEditor.setValue(query)
}, [query])`,
);
}
// @ts-expect-error -- runtime check
if (props.variables) {
throw new TypeError(
'The `variables` prop has been removed. Use `initialVariables` prop instead, or set value programmatically using:\n' +
`
const variableEditor = useGraphiQL(state => state.variableEditor)

useEffect(() => {
variableEditor.setValue(variables)
}, [variables])`,
);
}
// @ts-expect-error -- runtime check
if (props.headers) {
throw new TypeError(
'The `headers` prop has been removed. Use `initialHeaders` prop instead, or set value programmatically using:\n' +
`
const headerEditor = useGraphiQL(state => state.headerEditor)

useEffect(() => {
headerEditor.setValue(headers)
}, [headers])`,
);
}
// @ts-expect-error -- runtime check
if (props.response) {
throw new TypeError(
'The `response` prop has been removed. Set value programmatically using:\n' +
`
const responseEditor = useGraphiQL(state => state.responseEditor)

useEffect(() => {
responseEditor.setValue(response)
}, [response])`,
);
}
return (
Expand All @@ -82,14 +124,9 @@ export const GraphiQLProvider: FC<GraphiQLProviderProps> = ({
);
};

interface SynchronizeValueProps
extends Pick<EditorProps, 'headers' | 'query' | 'response' | 'variables'> {
children: ReactNode;
}

const InnerGraphiQLProvider: FC<InnerGraphiQLProviderProps> = ({
defaultHeaders,
defaultQuery,
defaultQuery = DEFAULT_QUERY,
defaultTabs,
externalFragments,
onEditOperationName,
Expand All @@ -114,6 +151,7 @@ const InnerGraphiQLProvider: FC<InnerGraphiQLProviderProps> = ({
referencePlugin,
visiblePlugin,
children,

...props
}) => {
const storage = useStorage();
Expand All @@ -137,15 +175,14 @@ const InnerGraphiQLProvider: FC<InnerGraphiQLProviderProps> = ({

function getInitialState() {
// We only need to compute it lazily during the initial render.
const query = props.query ?? storage.get(STORAGE_KEY.query) ?? null;
const query = props.initialQuery ?? storage.get(STORAGE_KEY.query);
const variables =
props.variables ?? storage.get(STORAGE_KEY.variables) ?? null;
const headers = props.headers ?? storage.get(STORAGE_KEY.headers) ?? null;
const response = props.response ?? '';
props.initialVariables ?? storage.get(STORAGE_KEY.variables);
const headers = props.initialHeaders ?? storage.get(STORAGE_KEY.headers);

const { tabs, activeTabIndex } = getDefaultTabState({
defaultHeaders,
defaultQuery: defaultQuery ?? DEFAULT_QUERY,
defaultQuery,
defaultTabs,
headers,
query,
Expand All @@ -169,7 +206,6 @@ const InnerGraphiQLProvider: FC<InnerGraphiQLProviderProps> = ({
initialHeaders: headers ?? defaultHeaders ?? '',
initialQuery:
query ?? (activeTabIndex === 0 ? tabs[0]!.query : null) ?? '',
initialResponse: response,
initialVariables: variables ?? '',
onCopyQuery,
onEditOperationName,
Expand Down Expand Up @@ -289,34 +325,15 @@ const InnerGraphiQLProvider: FC<InnerGraphiQLProviderProps> = ({

return (
<GraphiQLContext.Provider value={storeRef}>
<SynchronizeValue {...props}>{children}</SynchronizeValue>
{children}
</GraphiQLContext.Provider>
);
};

const SynchronizeValue: FC<SynchronizeValueProps> = ({
children,
headers,
query,
response,
variables,
}) => {
const { headerEditor, queryEditor, responseEditor, variableEditor } =
useGraphiQL(
pick('headerEditor', 'queryEditor', 'responseEditor', 'variableEditor'),
);

useSynchronizeValue(headerEditor, headers);
useSynchronizeValue(queryEditor, query);
useSynchronizeValue(responseEditor, response);
useSynchronizeValue(variableEditor, variables);
return children as ReactElement;
};

export function useGraphiQL<T>(selector: (state: SlicesWithActions) => T): T {
const store = useContext(GraphiQLContext);
if (!store) {
throw new Error('Missing `GraphiQLContext.Provider` in the tree');
throw new Error('Missing `GraphiQLContext.Provider` in the tree.');
}
return useStore(store.current, useShallow(selector));
}
Expand Down
4 changes: 0 additions & 4 deletions packages/graphiql-react/src/components/query-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,6 @@ export const QueryEditor: FC<QueryEditorProps> = ({
storage.set(STORAGE_KEY.query, query);

const operationFacts = getAndUpdateOperationFacts(editor);
if (operationFacts?.operationName !== undefined) {
storage.set(STORAGE_KEY.operationName, operationFacts.operationName);
}

// Invoke callback props only after the operation facts have been updated
onEdit?.(query, operationFacts?.documentAST);
if (
Expand Down
18 changes: 4 additions & 14 deletions packages/graphiql-react/src/components/response-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,9 @@ export const ResponseEditor: FC<ResponseEditorProps> = ({
...props
}) => {
const { setEditor, run } = useGraphiQLActions();
const { fetchError, validationErrors, initialResponse, responseEditor } =
useGraphiQL(
pick(
'fetchError',
'validationErrors',
'initialResponse',
'responseEditor',
),
);
const { fetchError, validationErrors, responseEditor } = useGraphiQL(
pick('fetchError', 'validationErrors', 'responseEditor'),
);
const ref = useRef<HTMLDivElement>(null!);
useEffect(() => {
if (fetchError) {
Expand All @@ -59,11 +53,7 @@ export const ResponseEditor: FC<ResponseEditorProps> = ({
}, [responseEditor, fetchError, validationErrors]);

useEffect(() => {
const model = getOrCreateModel({
uri: RESPONSE_URI,
value: initialResponse,
});
// Build the editor
const model = getOrCreateModel({ uri: RESPONSE_URI, value: '' });
const editor = createEditor(ref, {
model,
readOnly: true,
Expand Down
1 change: 0 additions & 1 deletion packages/graphiql-react/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const STORAGE_KEY = {
query: 'query',
variables: 'variables',
tabs: 'tabState',
operationName: 'operationName',
persistHeaders: 'shouldPersistHeaders',
theme: 'theme',
} as const;
Expand Down
Loading
Loading