Skip to content

Commit

Permalink
feat: Add focusPolling option to disable refetching if tab is inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-kumawat committed Nov 29, 2023
1 parent d470c96 commit 846a741
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/ObservableQuery.ts
Expand Up @@ -589,7 +589,7 @@ once, rather than every time you call fetchMore.`);
},
// Avoid polling during SSR and when the query is already in flight.
!queryManager.ssrMode && (
() => !isNetworkRequestInFlight(this.queryInfo.networkStatus))
() => !isNetworkRequestInFlight(this.queryInfo.networkStatus) && (!this.options.focusPolling || !document.hidden))
);
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/watchQueryOptions.ts
Expand Up @@ -115,6 +115,10 @@ export interface WatchQueryOptions<TVariables = OperationVariables>
* Specifies the {@link FetchPolicy} to be used after this query has completed.
*/
nextFetchPolicy?: WatchQueryFetchPolicy;
/**
* Specifies if refetching of query should be enabled if window is focused, ie, `document.hidden: true`.
*/
focusPolling?: boolean;
}

export interface FetchMoreQueryOptions<TVariables, K extends keyof TVariables> {
Expand Down
1 change: 1 addition & 0 deletions src/react/types/types.ts
Expand Up @@ -36,6 +36,7 @@ export interface BaseQueryOptions<TVariables = OperationVariables> {
nextFetchPolicy?: WatchQueryFetchPolicy;
errorPolicy?: ErrorPolicy;
pollInterval?: number;
focusPolling?: boolean;
client?: ApolloClient<any>;
notifyOnNetworkStatusChange?: boolean;
context?: Context;
Expand Down

0 comments on commit 846a741

Please sign in to comment.