Skip to content

Commit 6e5d5fc

Browse files
authored
graphiql 5: fix color in the F1 popup should be graphiql primary color (#4078)
* fix color in the F1 popup should be graphiql primary color * upd * upd * upd * increase test timeout
1 parent 1dfc857 commit 6e5d5fc

File tree

10 files changed

+150
-39
lines changed

10 files changed

+150
-39
lines changed

.changeset/twenty-walls-share.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphiql/react': minor
3+
'graphiql': patch
4+
---
5+
6+
fix color in the F1 popup should be graphiql primary color and add deprecated exports for `useEditorStore`, `useExecutionStore`, `usePluginStore` and `useSchemaStore`

packages/graphiql-react/src/components/provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ const InnerGraphiQLProvider: FC<GraphiQLProviderProps> = ({
346346
}, [
347347
schema,
348348
dangerouslyAssumeSchemaIsValid,
349-
fetcher, // should refresh schema with new fetcher after a fetchError
349+
fetcher, // should refresh schema with a new fetcher after a fetchError
350350
]);
351351

352352
/**

packages/graphiql-react/src/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,15 @@ const getBaseColors = (
200200
'editorLink.activeForeground': colors.primary[theme], // Color of active links
201201
'editorHoverWidget.background': colors.bg[theme], // Background color of the editor hover
202202
'list.hoverBackground': colors.primaryBg[theme], // List/Tree background when hovering over items using the mouse
203+
'list.highlightForeground': colors.primary[theme],
204+
'list.focusHighlightForeground': colors.primary[theme],
203205
'menu.background': colors.bg[theme], // Background color of the context menu
204206

205207
'editorSuggestWidget.background': colors.bg[theme], // Background color of the suggest widget
206208
'editorSuggestWidget.selectedBackground': colors.primaryBg[theme], // Background color of the selected entry in the suggest widget
207209
'editorSuggestWidget.selectedForeground': colors.primary[theme], // Foreground color of the selected entry in the suggest widget
208210
'quickInput.background': colors.bg[theme],
209-
'quickInputList.focusForeground': colors.primary[theme],
211+
'quickInputList.focusForeground': theme === 'dark' ? '#ffffff' : '#444444',
210212
'highlighted.label': colors.primary[theme],
211213
'quickInput.widget': colors.primary[theme],
212214
highlight: colors.primary[theme],

packages/graphiql-react/src/deprecated.ts

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
/* eslint-disable @typescript-eslint/no-deprecated */
2+
13
import { useGraphiQL, useGraphiQLActions } from './components';
24
import { pick } from './utility';
5+
import type { MonacoEditor } from './types';
36

47
/**
58
* @deprecated Use `const { prettifyEditors } = useGraphiQLActions()` instead.
@@ -25,13 +28,66 @@ export function useMergeQuery() {
2528
return mergeQuery;
2629
}
2730

31+
/**
32+
* @deprecated Use `useGraphiQLActions` and `useGraphiQL` hooks instead.
33+
*/
34+
export function useEditorContext() {
35+
const {
36+
addTab,
37+
changeTab,
38+
moveTab,
39+
closeTab,
40+
updateActiveTabValues,
41+
setEditor,
42+
setOperationName,
43+
setShouldPersistHeaders,
44+
} = useGraphiQLActions();
45+
46+
const setHeaderEditor = (headerEditor: MonacoEditor) =>
47+
setEditor({ headerEditor });
48+
const setQueryEditor = (queryEditor: MonacoEditor) =>
49+
setEditor({ queryEditor });
50+
const setResponseEditor = (responseEditor: MonacoEditor) =>
51+
setEditor({ responseEditor });
52+
const setVariableEditor = (variableEditor: MonacoEditor) =>
53+
setEditor({ variableEditor });
54+
55+
const values = useGraphiQL(
56+
pick(
57+
'headerEditor',
58+
'queryEditor',
59+
'responseEditor',
60+
'variableEditor',
61+
'initialHeaders',
62+
'initialQuery',
63+
'initialVariables',
64+
'externalFragments',
65+
'shouldPersistHeaders',
66+
),
67+
);
68+
return {
69+
addTab,
70+
changeTab,
71+
moveTab,
72+
closeTab,
73+
updateActiveTabValues,
74+
setHeaderEditor,
75+
setQueryEditor,
76+
setResponseEditor,
77+
setVariableEditor,
78+
setOperationName,
79+
setShouldPersistHeaders,
80+
...values,
81+
};
82+
}
83+
2884
/**
2985
* @deprecated Use `useGraphiQLActions` and `useGraphiQL` hooks instead.
3086
*/
3187
export function useExecutionContext() {
3288
const { run, stop } = useGraphiQLActions();
3389
const values = useGraphiQL(state => ({
34-
isFetching: state.isIntrospecting,
90+
isFetching: state.isFetching,
3591
isSubscribed: Boolean(state.subscription),
3692
operationName: state.operationName,
3793
}));
@@ -59,9 +115,12 @@ export function usePluginContext() {
59115
*/
60116
export function useSchemaContext() {
61117
const { introspect } = useGraphiQLActions();
62-
const values = useGraphiQL(
63-
pick('fetchError', 'isFetching', 'schema', 'validationErrors'),
64-
);
118+
const values = useGraphiQL(state => ({
119+
isFetching: state.isIntrospecting,
120+
fetchError: state.fetchError,
121+
schema: state.schema,
122+
validationErrors: state.validationErrors,
123+
}));
65124
return {
66125
introspect,
67126
...values,
@@ -76,7 +135,7 @@ export const useStorage = () => useGraphiQL(state => state.storage);
76135
/**
77136
* @deprecated Use `const storage = useGraphiQL(state => state.storage)` instead.
78137
*/
79-
export const useStorageContext = useStorage; // eslint-disable-line @typescript-eslint/no-deprecated
138+
export const useStorageContext = useStorage;
80139

81140
/**
82141
* @deprecated Use `useGraphiQLActions` and `useGraphiQL` hooks instead.
@@ -89,3 +148,23 @@ export function useTheme() {
89148
theme,
90149
};
91150
}
151+
152+
/**
153+
* @deprecated Use `useGraphiQLActions` and `useGraphiQL` hooks instead.
154+
*/
155+
export const useEditorStore = useEditorContext;
156+
157+
/**
158+
* @deprecated Use `useGraphiQLActions` and `useGraphiQL` hooks instead.
159+
*/
160+
export const useExecutionStore = useExecutionContext;
161+
162+
/**
163+
* @deprecated Use `useGraphiQLActions` and `useGraphiQL` hooks instead.
164+
*/
165+
export const usePluginStore = usePluginContext;
166+
167+
/**
168+
* @deprecated Use `useGraphiQLActions` and `useGraphiQL` hooks instead.
169+
*/
170+
export const useSchemaStore = useSchemaContext;

packages/graphiql-react/src/stores/editor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import { STORAGE_KEY } from '../constants';
2222

2323
export interface EditorSlice extends TabsState {
2424
/**
25-
* Unique ID of the GraphiQL instance, which will be suffixed to the URIs for operations, variables, headers, and responses.
25+
* Unique ID of the GraphiQL instance, which will be suffixed to the URIs for operations,
26+
* variables, headers, and response editors.
2627
*
2728
* @see https://github.com/microsoft/monaco-editor#uris
2829
*/

packages/graphiql-react/src/stores/theme.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ type MonacoTheme =
1212
export interface ThemeSlice {
1313
theme: Theme;
1414

15-
editorTheme: {
16-
dark: MonacoTheme;
17-
light: MonacoTheme;
18-
};
19-
2015
monacoTheme?: MonacoTheme;
2116
}
2217

@@ -37,11 +32,14 @@ export interface ThemeProps {
3732
* Sets the color theme for the monaco editors.
3833
* @default { dark: 'graphiql-DARK', light: 'graphiql-LIGHT' }
3934
*/
40-
editorTheme?: ThemeSlice['editorTheme'];
35+
editorTheme?: {
36+
dark: MonacoTheme;
37+
light: MonacoTheme;
38+
};
4139
}
4240

4341
type CreateThemeSlice = (
44-
initial: Pick<ThemeSlice, 'editorTheme'>,
42+
initial: Pick<ThemeProps, 'editorTheme'>,
4543
) => StateCreator<
4644
SlicesWithActions,
4745
[],
@@ -51,25 +49,26 @@ type CreateThemeSlice = (
5149
}
5250
>;
5351

54-
export const createThemeSlice: CreateThemeSlice = initial => (set, get) => ({
55-
theme: null,
56-
...initial,
57-
actions: {
58-
setTheme(theme) {
59-
const { storage, editorTheme } = get();
60-
storage.set(STORAGE_KEY.theme, theme ?? '');
61-
document.body.classList.remove('graphiql-light', 'graphiql-dark');
62-
if (theme) {
63-
document.body.classList.add(`graphiql-${theme}`);
64-
}
65-
const { monaco } = monacoStore.getState();
66-
const resolvedTheme = theme ?? getSystemTheme();
67-
const monacoTheme = editorTheme[resolvedTheme];
68-
monaco?.editor.setTheme(monacoTheme);
69-
set({ theme, monacoTheme });
52+
export const createThemeSlice: CreateThemeSlice =
53+
({ editorTheme }) =>
54+
(set, get) => ({
55+
theme: null,
56+
actions: {
57+
setTheme(theme) {
58+
const { storage } = get();
59+
storage.set(STORAGE_KEY.theme, theme ?? '');
60+
document.body.classList.remove('graphiql-light', 'graphiql-dark');
61+
if (theme) {
62+
document.body.classList.add(`graphiql-${theme}`);
63+
}
64+
const { monaco } = monacoStore.getState();
65+
const resolvedTheme = theme ?? getSystemTheme();
66+
const monacoTheme = editorTheme![resolvedTheme];
67+
monaco?.editor.setTheme(monacoTheme);
68+
set({ theme, monacoTheme });
69+
},
7070
},
71-
},
72-
});
71+
});
7372

7473
/**
7574
* Get the resolved theme - dark or light

packages/graphiql/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ _/ˈɡrafək(ə)l/_ A graphical interactive in-browser GraphQL IDE.
5454

5555
## Getting started
5656

57-
> If you're looking to upgrade from `graphiql@1.x` to `graphiql@2`, check out
58-
> the [migration guide](../../docs/migration/graphiql-2.0.0.md)!
57+
- [Migration guide to GraphiQL 2](../../docs/migration/graphiql-2.0.0.md)
58+
- [Migration guide to GraphiQL 4](../../docs/migration/graphiql-4.0.0.md)
59+
- [Migration guide to GraphiQL 5](../../docs/migration/graphiql-5.0.0.md)
5960

6061
### CDN usage
6162

packages/graphiql/setup-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ vi.mock('zustand');
88
vi.mock('monaco-editor');
99

1010
// Since we load `monaco-editor` dynamically, we need to allow more time for tests that assert editor values
11-
configure({ asyncUtilTimeout: 8_000 });
11+
configure({ asyncUtilTimeout: 9_000 });

packages/graphiql/src/GraphiQL.spec.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,24 @@ describe('GraphiQL', () => {
655655
});
656656

657657
it('should support multiple instances', async () => {
658+
const queryEditors: Record<0 | 1, MonacoEditor> = Object.create(null);
659+
660+
const HookConsumer: FC<{ id: 0 | 1 }> = ({ id }) => {
661+
const $queryEditor = useGraphiQL(state => state.queryEditor);
662+
useEffect(() => {
663+
queryEditors[id] = $queryEditor!;
664+
}, [$queryEditor, id]);
665+
return null;
666+
};
667+
658668
const { container, getAllByLabelText } = render(
659669
<>
660-
<GraphiQL fetcher={noOpFetcher} />
661-
<GraphiQL fetcher={noOpFetcher} />
670+
<GraphiQL fetcher={noOpFetcher}>
671+
<HookConsumer id={0} />
672+
</GraphiQL>
673+
<GraphiQL fetcher={noOpFetcher}>
674+
<HookConsumer id={1} />
675+
</GraphiQL>
662676
</>,
663677
);
664678
const [firstEl, secondEl] = container.querySelectorAll(
@@ -685,6 +699,15 @@ describe('GraphiQL', () => {
685699
// Editor store
686700
expect(firstEl!.querySelectorAll('.graphiql-tab').length).toBe(2);
687701
expect(secondEl!.querySelectorAll('.graphiql-tab').length).toBe(1);
702+
703+
// Query
704+
queryEditors[0].setValue('{__typename}');
705+
queryEditors[1].setValue('bar');
706+
const editors = container.querySelectorAll<HTMLDivElement>(
707+
'.graphiql-query-editor .monaco-scrollable-element',
708+
);
709+
expect(editors[0]!.textContent).toBe('{__typename}');
710+
expect(editors[1]!.textContent).toBe('bar');
688711
});
689712
});
690713

packages/graphiql/vitest.config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineConfig({
99
environment: 'jsdom',
1010
setupFiles: ['./setup-files.ts', './setup-window.ts'],
1111
// Since we increased `waitFor` timeout in setup-files.ts
12-
testTimeout: 8_000,
12+
testTimeout: 9_000,
1313
alias: [
1414
{
1515
// Fixes Error: Failed to resolve entry for package "monaco-editor". The package may have incorrect main/module/exports specified in its package.json.

0 commit comments

Comments
 (0)