Skip to content

Commit 170fcbc

Browse files
committed
Prioritize use of defaultHeaders if headers is nullish
1 parent ea1905d commit 170fcbc

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/graphiql-react/src/editor/context.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,14 @@ export function EditorContextProvider(props: EditorContextProviderProps) {
360360
headerEditor,
361361
responseEditor,
362362
});
363+
const { onTabChange, defaultHeaders, children } = props;
363364
const setEditorValues = useSetEditorValues({
364365
queryEditor,
365366
variableEditor,
366367
headerEditor,
367368
responseEditor,
369+
defaultHeaders,
368370
});
369-
const { onTabChange, defaultHeaders, children } = props;
370371

371372
const addTab = useCallback<EditorContextType['addTab']>(() => {
372373
setTabState(current => {

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,13 @@ export function useSetEditorValues({
258258
variableEditor,
259259
headerEditor,
260260
responseEditor,
261+
defaultHeaders,
261262
}: {
262263
queryEditor: CodeMirrorEditorWithOperationFacts | null;
263264
variableEditor: CodeMirrorEditor | null;
264265
headerEditor: CodeMirrorEditor | null;
265266
responseEditor: CodeMirrorEditor | null;
267+
defaultHeaders?: string;
266268
}) {
267269
return useCallback(
268270
({
@@ -278,12 +280,12 @@ export function useSetEditorValues({
278280
}) => {
279281
queryEditor?.setValue(query ?? '');
280282
variableEditor?.setValue(variables ?? '');
281-
if (headerEditor && headers?.length) {
282-
headerEditor.setValue(headers);
283+
if (headerEditor && (headers?.length || defaultHeaders?.length)) {
284+
headerEditor.setValue(headers ?? defaultHeaders ?? '');
283285
}
284286
responseEditor?.setValue(response ?? '');
285287
},
286-
[headerEditor, queryEditor, responseEditor, variableEditor],
288+
[headerEditor, queryEditor, responseEditor, variableEditor, defaultHeaders],
287289
);
288290
}
289291

0 commit comments

Comments
 (0)