Skip to content

Commit fb22d06

Browse files
committed
feat(useQuery): forward networkStatus for queries not using suspense
1 parent 8e34e01 commit fb22d06

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/useQuery.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
FetchMoreOptions,
66
FetchMoreQueryOptions,
77
FetchPolicy,
8+
NetworkStatus,
89
ObservableQuery,
910
OperationVariables,
1011
QueryOptions,
@@ -27,6 +28,8 @@ export interface QueryHookState<TData>
2728
'error' | 'errors' | 'loading' | 'partial'
2829
> {
2930
data?: TData;
31+
// networkStatus is undefined for skipped queries or the ones using suspense
32+
networkStatus: NetworkStatus | undefined;
3033
}
3134

3235
export interface QueryHookOptions<TVariables>
@@ -134,6 +137,10 @@ export function useQuery<TData = any, TVariables = OperationVariables>(
134137
: result.error,
135138
errors: result.errors,
136139
loading: result.loading,
140+
// don't try to return `networkStatus` when suspense it's used
141+
// because it's unreliable in that case
142+
// https://github.com/trojanowski/react-apollo-hooks/pull/68
143+
networkStatus: suspend ? undefined : result.networkStatus,
137144
partial: result.partial,
138145
};
139146
},
@@ -186,6 +193,7 @@ export function useQuery<TData = any, TVariables = OperationVariables>(
186193
data: undefined,
187194
error: undefined,
188195
loading: false,
196+
networkStatus: undefined,
189197
};
190198
}
191199

0 commit comments

Comments
 (0)