Skip to content

Commit

Permalink
Prioritize use of defaultHeaders if headers is nullish
Browse files Browse the repository at this point in the history
  • Loading branch information
klippx committed Apr 9, 2024
1 parent c9694df commit 94b09ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/graphiql-react/src/editor/context.tsx
Expand Up @@ -360,13 +360,14 @@ export function EditorContextProvider(props: EditorContextProviderProps) {
headerEditor,
responseEditor,
});
const { onTabChange, defaultHeaders, children } = props;
const setEditorValues = useSetEditorValues({
queryEditor,
variableEditor,
headerEditor,
responseEditor,
defaultHeaders,
});
const { onTabChange, defaultHeaders, children } = props;

const addTab = useCallback<EditorContextType['addTab']>(() => {
setTabState(current => {
Expand Down
8 changes: 5 additions & 3 deletions packages/graphiql-react/src/editor/tabs.ts
Expand Up @@ -258,11 +258,13 @@ export function useSetEditorValues({
variableEditor,
headerEditor,
responseEditor,
defaultHeaders,
}: {
queryEditor: CodeMirrorEditorWithOperationFacts | null;
variableEditor: CodeMirrorEditor | null;
headerEditor: CodeMirrorEditor | null;
responseEditor: CodeMirrorEditor | null;
defaultHeaders?: string;
}) {
return useCallback(
({
Expand All @@ -278,12 +280,12 @@ export function useSetEditorValues({
}) => {
queryEditor?.setValue(query ?? '');
variableEditor?.setValue(variables ?? '');
if (headerEditor && headers?.length) {
headerEditor.setValue(headers);
if (headerEditor && (headers?.length || defaultHeaders?.length)) {
headerEditor.setValue(headers ?? defaultHeaders ?? '');
}
responseEditor?.setValue(response ?? '');
},
[headerEditor, queryEditor, responseEditor, variableEditor],
[headerEditor, queryEditor, responseEditor, variableEditor, defaultHeaders],
);
}

Expand Down

0 comments on commit 94b09ad

Please sign in to comment.