Skip to content

Commit b2c3b90

Browse files
authored
feat!: exclude client mutations from refetch condition (#1178)
* Exclude client from stringified options Client's own options can be changed by a middleware which makes useQuery repeat the call * Update useQuery.ts * test: add test
1 parent 23fcd39 commit b2c3b90

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/graphql-hooks/src/useQuery.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ function useQuery<
6161
setCalledDuringSSR(true)
6262
}
6363

64-
const stringifiedAllOpts = JSON.stringify(allOpts)
64+
const { client: clientFromOpts, ...allOptsToStringify } = allOpts
65+
const stringifiedAllOpts = JSON.stringify(allOptsToStringify)
6566
React.useEffect(() => {
6667
if (allOpts.skip) {
6768
return

packages/graphql-hooks/test-jsdom/unit/useQuery.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,17 @@ describe('useQuery', () => {
379379
expect(mockClient2.ssrPromises[0]).resolves.toBe('data')
380380
})
381381

382+
it('does not run when client headers change', () => {
383+
const { rerender } = renderHook(() => useQuery(TEST_QUERY, { client: mockClient }), {
384+
wrapper: Wrapper
385+
})
386+
mockClient.headers = {
387+
trace_id: '123'
388+
}
389+
rerender()
390+
expect(mockQueryReq).toHaveBeenCalledTimes(1)
391+
})
392+
382393
describe('skip option', () => {
383394
it('should skip query if `skip` is `true`', () => {
384395
const queryReqMock = jest.fn()

0 commit comments

Comments
 (0)