Skip to content

Commit f2e694f

Browse files
authored
Revert "revert #3946 to have support …" (#3972)
This reverts commit 7054591.
1 parent 4c872dc commit f2e694f

File tree

24 files changed

+544
-744
lines changed

24 files changed

+544
-744
lines changed

packages/graphiql-plugin-doc-explorer/src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import {
1616
} from 'graphql';
1717
import { FC, ReactElement, ReactNode, useEffect } from 'react';
1818
import {
19-
createBoundedUseStore,
2019
SchemaContextType,
2120
useSchemaStore,
21+
createBoundedUseStore,
2222
} from '@graphiql/react';
2323
import { createStore } from 'zustand';
2424

packages/graphiql-plugin-explorer/src/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { CSSProperties, FC, useCallback } from 'react';
22
import {
33
GraphiQLPlugin,
4-
useEditorContext,
5-
useExecutionContext,
4+
useEditorStore,
5+
useExecutionStore,
66
useSchemaStore,
77
useOperationsEditorState,
88
useOptimisticState,
@@ -62,9 +62,9 @@ export type GraphiQLExplorerPluginProps = Omit<
6262
>;
6363

6464
const ExplorerPlugin: FC<GraphiQLExplorerPluginProps> = props => {
65-
const { setOperationName } = useEditorContext({ nonNull: true });
65+
const { setOperationName } = useEditorStore();
6666
const { schema } = useSchemaStore();
67-
const { run } = useExecutionContext({ nonNull: true });
67+
const { run } = useExecutionStore();
6868

6969
// handle running the current operation from the plugin
7070
const handleRunOperation = useCallback(

packages/graphiql-plugin-history/src/__tests__/components.spec.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { ComponentProps } from 'react';
44
import { formatQuery, HistoryItem } from '../components';
55
import { HistoryContextProvider } from '../context';
66
import {
7-
useEditorContext,
7+
useEditorStore,
88
Tooltip,
99
StorageContextProvider,
1010
} from '@graphiql/react';
@@ -16,15 +16,15 @@ vi.mock('@graphiql/react', async () => {
1616
const mockedSetHeaderEditor = vi.fn();
1717
return {
1818
...originalModule,
19-
useEditorContext() {
19+
useEditorStore() {
2020
return {
2121
queryEditor: { setValue: mockedSetQueryEditor },
2222
variableEditor: { setValue: mockedSetVariableEditor },
2323
headerEditor: { setValue: mockedSetHeaderEditor },
2424
tabs: [],
2525
};
2626
},
27-
useExecutionContext() {
27+
useExecutionStore() {
2828
return {};
2929
},
3030
};
@@ -78,12 +78,10 @@ function getMockProps(
7878
}
7979

8080
describe('QueryHistoryItem', () => {
81-
const mockedSetQueryEditor = useEditorContext()!.queryEditor!
82-
.setValue as Mock;
83-
const mockedSetVariableEditor = useEditorContext()!.variableEditor!
84-
.setValue as Mock;
85-
const mockedSetHeaderEditor = useEditorContext()!.headerEditor!
86-
.setValue as Mock;
81+
const store = useEditorStore();
82+
const mockedSetQueryEditor = store.queryEditor!.setValue as Mock;
83+
const mockedSetVariableEditor = store.variableEditor!.setValue as Mock;
84+
const mockedSetHeaderEditor = store.headerEditor!.setValue as Mock;
8785
beforeEach(() => {
8886
mockedSetQueryEditor.mockClear();
8987
mockedSetVariableEditor.mockClear();

packages/graphiql-plugin-history/src/components.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
StarFilledIcon,
88
StarIcon,
99
TrashIcon,
10-
useEditorContext,
10+
useEditorStore,
1111
Button,
1212
Tooltip,
1313
UnStyledButton,
@@ -112,10 +112,7 @@ type QueryHistoryItemProps = {
112112
export const HistoryItem: FC<QueryHistoryItemProps> = props => {
113113
const { editLabel, toggleFavorite, deleteFromHistory, setActive } =
114114
useHistoryActions();
115-
const { headerEditor, queryEditor, variableEditor } = useEditorContext({
116-
nonNull: true,
117-
caller: HistoryItem,
118-
});
115+
const { headerEditor, queryEditor, variableEditor } = useEditorStore();
119116
const inputRef = useRef<HTMLInputElement>(null);
120117
const buttonRef = useRef<HTMLButtonElement>(null);
121118
const [isEditable, setIsEditable] = useState(false);

packages/graphiql-plugin-history/src/context.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { FC, ReactElement, ReactNode, useEffect } from 'react';
33
import { createStore } from 'zustand';
44
import { HistoryStore, QueryStoreItem } from '@graphiql/toolkit';
55
import {
6-
useExecutionContext,
7-
useEditorContext,
6+
useExecutionStore,
7+
useEditorStore,
88
useStorage,
99
createBoundedUseStore,
1010
} from '@graphiql/react';
@@ -119,8 +119,8 @@ export const HistoryContextProvider: FC<HistoryContextProviderProps> = ({
119119
maxHistoryLength = 20,
120120
children,
121121
}) => {
122-
const { isFetching } = useExecutionContext({ nonNull: true });
123-
const { tabs, activeTabIndex } = useEditorContext({ nonNull: true });
122+
const { isFetching } = useExecutionStore();
123+
const { tabs, activeTabIndex } = useEditorStore();
124124
const activeTab = tabs[activeTabIndex];
125125
const storage = useStorage();
126126

packages/graphiql-react/src/editor/components/header-editor.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FC, useEffect } from 'react';
22
import { clsx } from 'clsx';
3-
import { useEditorContext } from '../context';
3+
import { useEditorStore } from '../context';
44
import { useHeaderEditor, UseHeaderEditorArgs } from '../header-editor';
55
import '../style/codemirror.css';
66
import '../style/fold.css';
@@ -18,11 +18,8 @@ export const HeaderEditor: FC<HeaderEditorProps> = ({
1818
isHidden,
1919
...hookArgs
2020
}) => {
21-
const { headerEditor } = useEditorContext({
22-
nonNull: true,
23-
caller: HeaderEditor,
24-
});
25-
const ref = useHeaderEditor(hookArgs, HeaderEditor);
21+
const headerEditor = useEditorStore(store => store.headerEditor);
22+
const ref = useHeaderEditor(hookArgs);
2623

2724
useEffect(() => {
2825
if (!isHidden) {

packages/graphiql-react/src/editor/components/response-editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import '../style/info.css';
66
import '../style/editor.css';
77

88
export const ResponseEditor: FC<UseResponseEditorArgs> = props => {
9-
const ref = useResponseEditor(props, ResponseEditor);
9+
const ref = useResponseEditor(props);
1010
return (
1111
<section
1212
className="result-window"

packages/graphiql-react/src/editor/components/variable-editor.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FC, useEffect } from 'react';
22
import { clsx } from 'clsx';
33

4-
import { useEditorContext } from '../context';
4+
import { useEditorStore } from '../context';
55
import { useVariableEditor, UseVariableEditorArgs } from '../variable-editor';
66

77
import '../style/codemirror.css';
@@ -22,11 +22,8 @@ export const VariableEditor: FC<VariableEditorProps> = ({
2222
isHidden,
2323
...hookArgs
2424
}) => {
25-
const { variableEditor } = useEditorContext({
26-
nonNull: true,
27-
caller: VariableEditor,
28-
});
29-
const ref = useVariableEditor(hookArgs, VariableEditor);
25+
const variableEditor = useEditorStore(store => store.variableEditor);
26+
const ref = useVariableEditor(hookArgs);
3027

3128
useEffect(() => {
3229
if (!isHidden) {

0 commit comments

Comments
 (0)