Skip to content

Commit

Permalink
Revert disabling refetches when fetchPolicy is standby
Browse files Browse the repository at this point in the history
Reverts 14cf342. Fixes #9101.
  • Loading branch information
brainkim committed Jan 19, 2022
1 parent ee55289 commit 1e42834
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export class ObservableQuery<
// (no-cache, network-only, or cache-and-network), override it with
// network-only to force the refetch for this fetchQuery call.
const { fetchPolicy } = this.options;
if (fetchPolicy === 'standby' || fetchPolicy === 'cache-and-network') {
if (fetchPolicy === 'cache-and-network') {
reobserveOptions.fetchPolicy = fetchPolicy;
} else if (fetchPolicy === 'no-cache') {
reobserveOptions.fetchPolicy = 'no-cache';
Expand Down
16 changes: 11 additions & 5 deletions src/react/hooks/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3071,7 +3071,8 @@ describe('useQuery Hook', () => {
expect(result.current.data).toEqual({ hello: 'world' });
});

it('should not refetch when skip is true', async () => {
// Amusingly, #8270 thinks this is a bug, but #9101 thinks this is not.
it('should refetch when skip is true', async () => {
const query = gql`{ hello }`;
const link = new ApolloLink(() => Observable.of({
data: { hello: 'world' },
Expand All @@ -3098,13 +3099,18 @@ describe('useQuery Hook', () => {
expect(result.current.data).toBe(undefined);
await expect(waitForNextUpdate({ timeout: 20 }))
.rejects.toThrow('Timed out');
result.current.refetch();
await expect(waitForNextUpdate({ timeout: 20 }))
.rejects.toThrow('Timed out');
const promise = result.current.refetch();
// TODO: Not really sure about who is causing this render.
await waitForNextUpdate();
expect(result.current.loading).toBe(false);
expect(result.current.data).toBe(undefined);
expect(requestSpy).toHaveBeenCalledTimes(0);
expect(requestSpy).toHaveBeenCalledTimes(1);
requestSpy.mockRestore();
expect(promise).resolves.toEqual({
data: {hello: "world"},
loading: false,
networkStatus: 7,
});
});
});

Expand Down

0 comments on commit 1e42834

Please sign in to comment.