Skip to content

[2] remove useQueryEditor, useVariableEditor, useHeaderEditor, useResponseEditor hooks #3950

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 159 commits into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
7c5f11f
use execution store
dimaMachina May 13, 2025
53cb535
upd
dimaMachina May 13, 2025
e52977e
upd
dimaMachina May 13, 2025
fcfd519
upd
dimaMachina May 13, 2025
8db47ce
upd
dimaMachina May 13, 2025
7589253
upd
dimaMachina May 13, 2025
9425ff8
upd
dimaMachina May 13, 2025
f0d728d
upd
dimaMachina May 13, 2025
7335522
upd
dimaMachina May 13, 2025
6ac226e
upd
dimaMachina May 13, 2025
7bf7e80
upd
dimaMachina May 13, 2025
b28cc14
upd
dimaMachina May 13, 2025
7a09053
upd
dimaMachina May 13, 2025
dba736e
upd
dimaMachina May 13, 2025
d16a30c
upd
dimaMachina May 13, 2025
58cb9eb
default query
dimaMachina May 13, 2025
518ed77
persist headers
dimaMachina May 13, 2025
0662a03
upd
dimaMachina May 13, 2025
cf1a268
upd
dimaMachina May 13, 2025
839d938
upd
dimaMachina May 13, 2025
f912245
upd
dimaMachina May 13, 2025
0abb0ec
upd
dimaMachina May 13, 2025
e8403f6
upd
dimaMachina May 13, 2025
5824175
upd
dimaMachina May 13, 2025
418b805
upd
dimaMachina May 13, 2025
7b9bc0b
upd
dimaMachina May 13, 2025
fec041b
upd
dimaMachina May 13, 2025
9afd50c
reduce rerenders
dimaMachina May 13, 2025
50b7ef3
add logs
dimaMachina May 13, 2025
82f6c09
try
dimaMachina May 13, 2025
7d9cd26
cleanup
dimaMachina May 13, 2025
30d298f
cspell
dimaMachina May 13, 2025
2e261ca
upd
dimaMachina May 14, 2025
7119c6a
upd
dimaMachina May 14, 2025
31241e2
upd
dimaMachina May 14, 2025
037485d
upd
dimaMachina May 14, 2025
13b008b
upd
dimaMachina May 14, 2025
93b1492
upd
dimaMachina May 14, 2025
5e572fd
upd
dimaMachina May 14, 2025
3648b78
upd
dimaMachina May 14, 2025
bc43eb3
upd
dimaMachina May 14, 2025
0595458
upd
dimaMachina May 14, 2025
24c2373
upd
dimaMachina May 14, 2025
384e7b0
upd
dimaMachina May 14, 2025
7a9224c
upd
dimaMachina May 14, 2025
727fd1a
upd
dimaMachina May 14, 2025
3ba26c5
upd
dimaMachina May 14, 2025
77303a1
upd
dimaMachina May 14, 2025
c1f402d
upd
dimaMachina May 14, 2025
7ca8fa1
upd
dimaMachina May 14, 2025
12cf600
upd
dimaMachina May 14, 2025
b0193b2
upd
dimaMachina May 14, 2025
576b52d
upd
dimaMachina May 14, 2025
e149cd3
upd
dimaMachina May 14, 2025
6a61215
upd
dimaMachina May 14, 2025
567cca6
upd
dimaMachina May 14, 2025
db445ec
upd
dimaMachina May 14, 2025
88a5be2
upd
dimaMachina May 14, 2025
9649e6d
upd
dimaMachina May 14, 2025
ced804c
upd
dimaMachina May 14, 2025
74c059f
upd
dimaMachina May 14, 2025
3580e94
upd
dimaMachina May 14, 2025
661df4b
upd
dimaMachina May 14, 2025
787d47c
upd
dimaMachina May 14, 2025
9a5e29f
upd
dimaMachina May 14, 2025
95e5e85
upd
dimaMachina May 14, 2025
27554e2
upd
dimaMachina May 14, 2025
454cb97
upd
dimaMachina May 14, 2025
ca53861
upd
dimaMachina May 14, 2025
5d07602
upd
dimaMachina May 14, 2025
a7ceaa8
upd
dimaMachina May 14, 2025
2bc1a06
upd
dimaMachina May 14, 2025
04747d3
upd
dimaMachina May 14, 2025
ef835fb
upd
dimaMachina May 14, 2025
6bcc55d
upd
dimaMachina May 14, 2025
6682497
upd
dimaMachina May 14, 2025
1fe7eaf
upd
dimaMachina May 14, 2025
7e85d71
upd
dimaMachina May 14, 2025
695832c
upd
dimaMachina May 14, 2025
c062b23
upd
dimaMachina May 14, 2025
9b3c029
upd
dimaMachina May 14, 2025
43e83d0
upd
dimaMachina May 14, 2025
efa078a
upd
dimaMachina May 14, 2025
a7d21a2
upd
dimaMachina May 14, 2025
df6bc60
Merge branch 'main' into v4-6
dimaMachina May 14, 2025
2723780
Merge branch 'v4-6' into v4-9
dimaMachina May 14, 2025
5207987
fixes
dimaMachina May 14, 2025
ed99173
fixes
dimaMachina May 14, 2025
0747d7e
fixes
dimaMachina May 14, 2025
f553781
fixes
dimaMachina May 14, 2025
39242be
fixes
dimaMachina May 14, 2025
2ecda33
upd
dimaMachina May 15, 2025
ad4a8a9
upd
dimaMachina May 15, 2025
0e8823f
upd
dimaMachina May 15, 2025
a83cf69
upd
dimaMachina May 15, 2025
62ea76e
upd
dimaMachina May 15, 2025
796aa20
upd
dimaMachina May 15, 2025
ce31c60
upd
dimaMachina May 15, 2025
0274e87
upd
dimaMachina May 15, 2025
65790ea
upd
dimaMachina May 15, 2025
78fc130
upd
dimaMachina May 15, 2025
6a14d7e
upd
dimaMachina May 15, 2025
b1ff040
upd
dimaMachina May 15, 2025
e42dd2d
upd
dimaMachina May 15, 2025
4be721b
upd
dimaMachina May 15, 2025
19bf02f
upd
dimaMachina May 15, 2025
b08df3c
upd
dimaMachina May 15, 2025
f43edcc
upd
dimaMachina May 15, 2025
9222dbf
upd
dimaMachina May 15, 2025
22693e7
upd
dimaMachina May 15, 2025
c1b09c8
upd
dimaMachina May 15, 2025
e8008ae
upd
dimaMachina May 15, 2025
00da1c8
upd
dimaMachina May 15, 2025
a6dda07
upd
dimaMachina May 15, 2025
8f92b6a
upd
dimaMachina May 15, 2025
f899b18
upd
dimaMachina May 15, 2025
e2ce749
upd
dimaMachina May 15, 2025
b7969bc
upd
dimaMachina May 15, 2025
1aab847
upd
dimaMachina May 15, 2025
980c83a
upd
dimaMachina May 15, 2025
1882e20
upd
dimaMachina May 15, 2025
fa90c0c
upd
dimaMachina May 15, 2025
036ebde
upd
dimaMachina May 15, 2025
3290391
upd
dimaMachina May 15, 2025
b78624a
upd
dimaMachina May 15, 2025
005091e
upd
dimaMachina May 15, 2025
154cb8b
upd
dimaMachina May 15, 2025
f799696
upd
dimaMachina May 15, 2025
9bb265f
upd
dimaMachina May 15, 2025
8a894da
upd
dimaMachina May 15, 2025
83825c3
upd
dimaMachina May 15, 2025
e78fa9a
upd
dimaMachina May 15, 2025
a785297
upd
dimaMachina May 15, 2025
d2f0d36
upd
dimaMachina May 15, 2025
e9c0567
upd
dimaMachina May 15, 2025
aa701c5
upd
dimaMachina May 15, 2025
639bc4c
upd
dimaMachina May 15, 2025
6f44cd8
upd
dimaMachina May 15, 2025
e4eb50c
prettier
dimaMachina May 15, 2025
14be107
upd
dimaMachina May 15, 2025
388495d
move plugins check to store
dimaMachina May 15, 2025
bc2c655
upd
dimaMachina May 15, 2025
7e937c3
upd
dimaMachina May 15, 2025
25ba8cc
refactor
dimaMachina May 15, 2025
319cb36
refactor
dimaMachina May 15, 2025
0623c2d
upd
dimaMachina May 15, 2025
f8cecc2
upd
dimaMachina May 15, 2025
7320d0d
upd
dimaMachina May 15, 2025
fe17c0b
upd
dimaMachina May 15, 2025
df29d87
upd
dimaMachina May 15, 2025
e63113b
upd
dimaMachina May 15, 2025
537a8f9
lint fix
dimaMachina May 15, 2025
5c1eec5
Merge branch 'main' into v4-9
dimaMachina May 20, 2025
c94a092
Merge branch 'v4-9' into v4-10
dimaMachina May 20, 2025
4173f0b
Merge branch 'graphiql-5' into v4-10
dimaMachina Jun 3, 2025
cb8c6a0
Delete .changeset/five-cars-roll.md
dimaMachina Jun 3, 2025
3eb9ae8
Merge branch 'graphiql-5' into v4-10
dimaMachina Jun 3, 2025
9adb63f
Update .changeset/warm-shoes-boil.md
dimaMachina Jun 3, 2025
f53f396
fix build
dimaMachina Jun 3, 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
16 changes: 16 additions & 0 deletions .changeset/warm-shoes-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@graphiql/react': minor
'@graphiql/plugin-history': minor
'@graphiql/plugin-doc-explorer': minor
'graphiql': patch
---

- remove `useQueryEditor`, `useVariableEditor`, `useHeaderEditor`, `useResponseEditor` hooks
- remove `UseHeaderEditorArgs`, `UseQueryEditorArgs`, `UseResponseEditorArgs`, `UseVariableEditorArgs` exports
- rename components
- `StorageContextProvider` => `StorageStore`
- `EditorContextProvider` => `EditorStore`
- `SchemaContextProvider` => `SchemaStore`
- `ExecutionContextProvider` => `ExecutionStore`
- `HistoryContextProvider` => `HistoryStore`
- `ExplorerContextProvider` => `ExplorerStore`
5 changes: 5 additions & 0 deletions packages/graphiql-plugin-doc-explorer/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# `@graphiql/plugin-doc-explorer`

## API

- `useDocExplorer`: Handles the state for the doc explorer
- `useDocExplorerActions`: Actions related to the doc explorer
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { act, render } from '@testing-library/react';
import { GraphQLInt, GraphQLObjectType, GraphQLSchema } from 'graphql';
import { FC, useEffect } from 'react';
import {
DocExplorerContextProvider,
DocExplorerStore,
useDocExplorer,
useDocExplorerActions,
} from '../../context';
import { DocExplorer } from '../doc-explorer';
import { schemaStore } from '../../../../graphiql-react/dist/schema';
import { schemaStore } from '../../../../graphiql-react/dist/stores/schema';

function makeSchema(fieldName = 'field') {
return new GraphQLSchema({
Expand Down Expand Up @@ -43,9 +43,9 @@ const withErrorSchemaContext = {

const DocExplorerWithContext: FC = () => {
return (
<DocExplorerContextProvider>
<DocExplorerStore>
<DocExplorer />
</DocExplorerContextProvider>
</DocExplorerStore>
);
};

Expand Down Expand Up @@ -109,9 +109,9 @@ describe('DocExplorer', () => {
schema: initialSchema,
});
const { container, rerender } = render(
<DocExplorerContextProvider>
<DocExplorerStore>
<SetInitialStack />
</DocExplorerContextProvider>,
</DocExplorerStore>,
);

// First proper render of doc explorer
Expand All @@ -122,9 +122,9 @@ describe('DocExplorer', () => {
});
});
rerender(
<DocExplorerContextProvider>
<DocExplorerStore>
<DocExplorer />
</DocExplorerContextProvider>,
</DocExplorerStore>,
);

const [title] = container.querySelectorAll('.graphiql-doc-explorer-title');
Expand All @@ -138,9 +138,9 @@ describe('DocExplorer', () => {
});
});
rerender(
<DocExplorerContextProvider>
<DocExplorerStore>
<DocExplorer />
</DocExplorerContextProvider>,
</DocExplorerStore>,
);
const [title2] = container.querySelectorAll('.graphiql-doc-explorer-title');
// Because `Query.field` still exists in the new schema, we can still render it
Expand Down Expand Up @@ -171,9 +171,9 @@ describe('DocExplorer', () => {
schema: initialSchema,
});
const { container, rerender } = render(
<DocExplorerContextProvider>
<DocExplorerStore>
<SetInitialStack />
</DocExplorerContextProvider>,
</DocExplorerStore>,
);

// First proper render of doc explorer
Expand All @@ -184,9 +184,9 @@ describe('DocExplorer', () => {
});
});
rerender(
<DocExplorerContextProvider>
<DocExplorerStore>
<DocExplorer />
</DocExplorerContextProvider>,
</DocExplorerStore>,
);

const title = container.querySelector('.graphiql-doc-explorer-title')!;
Expand All @@ -200,9 +200,9 @@ describe('DocExplorer', () => {
});
});
rerender(
<DocExplorerContextProvider>
<DocExplorerStore>
<DocExplorer />
</DocExplorerContextProvider>,
</DocExplorerStore>,
);
const title2 = container.querySelector('.graphiql-doc-explorer-title')!;
// Because `Query.field` doesn't exist anymore, the top-most item we can render is `Query`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { docExplorerStore } from '../../context';
import { TypeDocumentation } from '../type-documentation';
import { unwrapType } from './test-utils';
import { schemaStore } from '../../../../graphiql-react/dist/schema';
import { schemaStore } from '../../../../graphiql-react/dist/stores/schema';

const TypeDocumentationWithContext: FC<{ type: GraphQLNamedType }> = ({
type,
Expand Down
10 changes: 5 additions & 5 deletions packages/graphiql-plugin-doc-explorer/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from 'graphql';
import { FC, ReactElement, ReactNode, useEffect } from 'react';
import {
SchemaContextType,
SchemaReference,
useSchemaStore,
createBoundedUseStore,
} from '@graphiql/react';
Expand Down Expand Up @@ -45,7 +45,7 @@ export type DocExplorerNavStack = [
...DocExplorerNavStackItem[],
];

export type DocExplorerContextType = {
export type DocExplorerStoreType = {
/**
* A stack of navigation items. The last item in the list is the current one.
* This list always contains at least one item.
Expand All @@ -67,7 +67,7 @@ export type DocExplorerContextType = {
*/
reset(): void;
resolveSchemaReferenceToNavItem(
schemaReference: SchemaContextType['schemaReference'],
schemaReference: SchemaReference | null,
): void;
/**
* Replace the nav stack with an updated version using the new schema.
Expand All @@ -78,7 +78,7 @@ export type DocExplorerContextType = {

const INITIAL_NAV_STACK: DocExplorerNavStack = [{ name: 'Docs' }];

export const docExplorerStore = createStore<DocExplorerContextType>(
export const docExplorerStore = createStore<DocExplorerStoreType>(
(set, get) => ({
explorerNavStack: INITIAL_NAV_STACK,
actions: {
Expand Down Expand Up @@ -235,7 +235,7 @@ export const docExplorerStore = createStore<DocExplorerContextType>(
}),
);

export const DocExplorerContextProvider: FC<{
export const DocExplorerStore: FC<{
children: ReactNode;
}> = ({ children }) => {
const { schema, validationErrors, schemaReference } = useSchemaStore();
Expand Down
3 changes: 1 addition & 2 deletions packages/graphiql-plugin-doc-explorer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import { DocExplorer } from './components';
export * from './components';

export {
DocExplorerContextProvider,
DocExplorerStore,
useDocExplorer,
useDocExplorerActions,
} from './context';

export type {
DocExplorerContextType,
DocExplorerFieldDef,
DocExplorerNavStack,
DocExplorerNavStackItem,
Expand Down
5 changes: 5 additions & 0 deletions packages/graphiql-plugin-history/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# `@graphiql/plugin-history`

## API

- `useHistory`: Persists executed requests in storage
- `useHistoryActions`: Actions related to the history
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { fireEvent, render } from '@testing-library/react';
import type { ComponentProps } from 'react';
import { formatQuery, HistoryItem } from '../components';
import { HistoryContextProvider } from '../context';
import { HistoryStore } from '../context';
import { Tooltip, GraphiQLProvider } from '@graphiql/react';
import { editorStore } from '../../../graphiql-react/dist/editor/context';
import { editorStore } from '../../../graphiql-react/dist/stores/editor';

const mockQuery = /* GraphQL */ `
query Test($string: String) {
Expand All @@ -25,9 +25,9 @@ const QueryHistoryItemWithContext: typeof HistoryItem = props => {
return (
<Tooltip.Provider>
<GraphiQLProvider fetcher={vi.fn()}>
<HistoryContextProvider>
<HistoryStore>
<HistoryItem {...props} />
</HistoryContextProvider>
</HistoryStore>
</GraphiQLProvider>
</Tooltip.Provider>
);
Expand Down
25 changes: 14 additions & 11 deletions packages/graphiql-plugin-history/src/context.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// eslint-disable-next-line react/jsx-filename-extension -- TODO
import { FC, ReactElement, ReactNode, useEffect } from 'react';
import { createStore } from 'zustand';
import { HistoryStore, QueryStoreItem } from '@graphiql/toolkit';
import {
HistoryStore as ToolkitHistoryStore,
QueryStoreItem,
} from '@graphiql/toolkit';
import {
useExecutionStore,
useEditorStore,
useStorage,
createBoundedUseStore,
} from '@graphiql/react';

const historyStore = createStore<HistoryContextType>((set, get) => ({
const historyStore = createStore<HistoryStoreType>((set, get) => ({
historyStorage: null!,
actions: {
addToHistory(operation) {
Expand All @@ -36,8 +39,8 @@ const historyStore = createStore<HistoryContextType>((set, get) => ({
},
}));

type HistoryContextType = {
historyStorage: HistoryStore;
type HistoryStoreType = {
historyStorage: ToolkitHistoryStore;
actions: {
/**
* Add an operation to the history.
Expand Down Expand Up @@ -100,7 +103,7 @@ type HistoryContextType = {
};
};

type HistoryContextProviderProps = {
type HistoryStoreProps = {
children: ReactNode;
/**
* The maximum number of executed operations to store.
Expand All @@ -110,12 +113,12 @@ type HistoryContextProviderProps = {
};

/**
* The functions send the entire operation so users can customize their own application with
* <HistoryContext.Provider value={customizedFunctions} /> and get access to the operation plus
* any additional props they added for their needs (i.e., build their own functions that may save
* to a backend instead of localStorage and might need an id property added to the QueryStoreItem)
* The functions send the entire operation so users can customize their own application and get
* access to the operation plus any additional props they added for their needs (i.e., build their
* own functions that may save to a backend instead of localStorage and might need an id property
* added to the `QueryStoreItem`)
*/
export const HistoryContextProvider: FC<HistoryContextProviderProps> = ({
export const HistoryStore: FC<HistoryStoreProps> = ({
maxHistoryLength = 20,
children,
}) => {
Expand All @@ -125,7 +128,7 @@ export const HistoryContextProvider: FC<HistoryContextProviderProps> = ({
const storage = useStorage();

const historyStorage = // eslint-disable-line react-hooks/exhaustive-deps -- false positive, code is optimized by React Compiler
new HistoryStore(storage, maxHistoryLength);
new ToolkitHistoryStore(storage, maxHistoryLength);

useEffect(() => {
historyStore.setState({ historyStorage });
Expand Down
6 changes: 1 addition & 5 deletions packages/graphiql-plugin-history/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,4 @@ export const HISTORY_PLUGIN: GraphiQLPlugin = {

export { History };

export {
HistoryContextProvider,
useHistory,
useHistoryActions,
} from './context';
export { HistoryStore, useHistory, useHistoryActions } from './context';
23 changes: 10 additions & 13 deletions packages/graphiql-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,21 @@ Further details on how to use `@graphiql/react` can be found in the reference
implementation of a GraphQL IDE - Graph*i*QL - in the
[`graphiql` package](https://github.com/graphql/graphiql/blob/main/packages/graphiql/src/components/GraphiQL.tsx).

## Available contexts
## Available stores

There are multiple contexts that own different parts of the state that make up a
complete GraphQL IDE. For each context there is a provider component
(`<name>ContextProvider`) that makes sure the context is initialized and managed
There are multiple stores that own different parts of the state that make up a
complete GraphQL IDE. For each store there is a component
(`<name>Store`) that makes sure the store is initialized and managed
properly. These components contains all the logic related to state management.
In addition, for each context there is also a hook (`use<name>Context`) that
allows you to consume its current value.

Here is a list of all contexts that come with `@graphiql/react`
In addition, for each store, there is also a hook that
allows you to consume its current value:

- `StorageContext`: Provides a storage API that can be used to persist state in
- `useStorage`: Provides a storage API that can be used to persist state in
the browser (by default using `localStorage`)
- `EditorContext`: Manages all the editors and tabs
- `SchemaContext`: Fetches, validates and stores the GraphQL schema
- `ExecutionContext`: Executes GraphQL requests
- `HistoryContext`: Persists executed requests in storage
- `ExplorerContext`: Handles the state for the docs explorer
- `useEditorStore`: Manages all the editors and tabs
- `useSchemaStore`: Fetches, validates and stores the GraphQL schema
- `useExecutionStore`: Executes GraphQL requests

All context properties are documented using JSDoc comments. If you're using an
IDE like VSCode for development these descriptions will show up in auto-complete
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-react/src/editor/__tests__/tabs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
clearHeadersFromTabs,
STORAGE_KEY,
} from '../tabs';
import { storageStore } from '../../storage';
import { storageStore } from '../../stores/storage';

describe('createTab', () => {
it('creates with default title', () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/graphiql-react/src/editor/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import {
isNonNullType,
} from 'graphql';
import { markdown } from '../utility';
import { pluginStore } from '../plugin';
import { pluginStore, schemaStore } from '../stores';
import { importCodeMirror } from './common';
import { schemaStore } from '../schema';

/**
* Render a custom UI for CodeMirror's hint which includes additional info
Expand Down
33 changes: 0 additions & 33 deletions packages/graphiql-react/src/editor/components/header-editor.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions packages/graphiql-react/src/editor/components/index.ts

This file was deleted.

Loading
Loading