diff --git a/packages/graphiql-react/src/editor/context.tsx b/packages/graphiql-react/src/editor/context.tsx index a1a0fed849..339f84cf03 100644 --- a/packages/graphiql-react/src/editor/context.tsx +++ b/packages/graphiql-react/src/editor/context.tsx @@ -360,14 +360,7 @@ export function EditorContextProvider(props: EditorContextProviderProps) { headerEditor, responseEditor, }); - const { - onTabChange, - headers, - query, - defaultHeaders, - defaultQuery, - children, - } = props; + const { onTabChange, defaultHeaders, defaultQuery, children } = props; const setEditorValues = useSetEditorValues({ queryEditor, variableEditor, @@ -384,8 +377,8 @@ export function EditorContextProvider(props: EditorContextProviderProps) { tabs: [ ...updatedValues.tabs, createTab({ - headers: headers ?? defaultHeaders, - query: query ?? defaultQuery ?? DEFAULT_QUERY, + headers: defaultHeaders, + query: defaultQuery ?? DEFAULT_QUERY, }), ], activeTabIndex: updatedValues.tabs.length, @@ -396,8 +389,6 @@ export function EditorContextProvider(props: EditorContextProviderProps) { return updated; }); }, [ - headers, - query, defaultHeaders, defaultQuery, onTabChange, diff --git a/packages/graphiql/cypress/e2e/headers.cy.ts b/packages/graphiql/cypress/e2e/headers.cy.ts index da453b052d..7e4df95b56 100644 --- a/packages/graphiql/cypress/e2e/headers.cy.ts +++ b/packages/graphiql/cypress/e2e/headers.cy.ts @@ -3,7 +3,9 @@ const DEFAULT_HEADERS = '{"foo":2}'; describe('Headers', () => { describe('`defaultHeaders`', () => { it('should have default headers while open new tabs', () => { - cy.visit(`/?query={test}&defaultHeaders=${DEFAULT_HEADERS}`); + cy.visit( + `/?query={test}&defaultHeaders=${DEFAULT_HEADERS}&defaultQuery=`, + ); cy.assertHasValues({ query: '{test}', headersString: DEFAULT_HEADERS }); cy.get('.graphiql-tab-add').click(); cy.assertHasValues({ query: '', headersString: DEFAULT_HEADERS }); @@ -14,7 +16,7 @@ describe('Headers', () => { it('in case `headers` and `defaultHeaders` are set, `headers` should be on 1st tab and `defaultHeaders` for other opened tabs', () => { const HEADERS = '{"bar":true}'; cy.visit( - `/?query={test}&defaultHeaders=${DEFAULT_HEADERS}&headers=${HEADERS}`, + `/?query={test}&defaultHeaders=${DEFAULT_HEADERS}&headers=${HEADERS}&defaultQuery=`, ); cy.assertHasValues({ query: '{test}', headersString: HEADERS }); cy.get('.graphiql-tab-add').click(); diff --git a/packages/graphiql/cypress/e2e/tabs.cy.ts b/packages/graphiql/cypress/e2e/tabs.cy.ts index 13cdba3f06..007bd2d5de 100644 --- a/packages/graphiql/cypress/e2e/tabs.cy.ts +++ b/packages/graphiql/cypress/e2e/tabs.cy.ts @@ -1,6 +1,6 @@ describe('Tabs', () => { it('Should store editor contents when switching between tabs', () => { - cy.visit('/?query='); + cy.visit('/?defaultQuery=&query='); // Assert that no tab visible when there's only one session cy.get('#graphiql-session-tab-0').should('not.exist'); diff --git a/packages/graphiql/resources/renderExample.js b/packages/graphiql/resources/renderExample.js index 208d6accc2..b3276303dd 100644 --- a/packages/graphiql/resources/renderExample.js +++ b/packages/graphiql/resources/renderExample.js @@ -94,5 +94,6 @@ root.render( parameters.confirmCloseTab === 'true' ? confirmCloseTab : undefined, onTabChange, forcedTheme: parameters.forcedTheme, + defaultQuery: parameters.defaultQuery, }), );