Major Changes
-
#12649
0be92ad
Thanks @jerelmiller! - TheTData
generic provided to types that return adataState
property is now modified by the givenDataState
generic instead of passing a modifiedTData
type. For example, aQueryRef
that could return partial data was defined asQueryRef<DeepPartial<TData>, TVariables>
. NowTData
should be provided unmodified and a set of allowed states should be given instead:QueryRef<TData, TVariables, 'complete' | 'streaming' | 'partial'>
.To migrate, use the following guide to replace your type with the right set of states (all types listed below are changed the same way):
- QueryRef<TData, TVariables> // `QueryRef`'s default is 'complete' | 'streaming' so this can also be left alone if you prefer // All other types affected by this change default to all states + QueryRef<TData, TVariables> + QueryRef<TData, TVariables, 'complete' | 'streaming'> - QueryRef<TData | undefined, TVariables> + QueryRef<TData, TVariables, 'complete' | 'streaming' | 'empty'> - QueryRef<DeepPartial<TData>, TVariables> + QueryRef<TData, TVariables, 'complete' | 'streaming' | 'partial'> - QueryRef<DeepPartial<TData> | undefined, TVariables> + QueryRef<TData, TVariables, 'complete' | 'streaming' | 'partial' | 'empty'>
The following types are affected. Provide the allowed
dataState
values to theTDataState
generic:ApolloQueryResult
QueryRef
PreloadedQueryRef
useLazyQuery.Result
useQuery.Result
useReadQuery.Result
useSuspenseQuery.Result
All
*QueryRef
types default tocomplete | streaming
states while the rest of the types default to'complete' | 'streaming' | 'partial' | 'empty'
states. You shouldn't need to provide the states unless you need to either allow for partial data/empty values (*QueryRef
) or a restricted set of states. -
#12649
0be92ad
Thanks @jerelmiller! - Remove the deprecatedQueryReference
type. Please useQueryRef
instead. -
#12633
9bfb51f
Thanks @phryneas! - If theexecute
function ofuseLazyQuery
is executed, previously started queries
from the sameuseLazyQuery
usage will be rejected with anAbortError
unless
.retain()
is called on the promise returned by previousexecute
calls.Please keep in mind that
useLazyQuery
is primarily meant as a means to synchronize
your component to the status of a query and that it's purpose it not to make a
series of network calls.
If you plan on making a series of network calls without the need to synchronize
the result with your component, consider usingApolloClient.query
instead.
Minor Changes
-
#12633
9bfb51f
Thanks @phryneas! -ObservableQuery.refetch
andObservableQuery.reobserve
and theexecute
function ofuseLazyQuery
now return a
ResultPromise
with an additional.retain
method.
If this method is called, the underlying network operation will be kept running even if theObservableQuery
itself does
not require the result anymore, and the Promise will resolve with the final result instead of resolving with an intermediate
result in the case of early cancellation. -
#12649
0be92ad
Thanks @jerelmiller! - Add a newdataState
property that determines the completeness of thedata
property.dataState
helps narrow the type ofdata
.dataState
is now emitted fromObservableQuery
and returned from all React hooks that return adata
property.The
dataState
values are:empty
: No data could be fulfilled from the cache or the result is incomplete.data
isundefined
.partial
: Some data could be fulfilled from the cache butdata
is incomplete. This is only possible whenreturnPartialData
istrue
.streaming
:data
is incomplete as a result of a deferred query and the result is still streaming in.complete
:data
is a fully satisfied query result fulfilled either from the cache or network.
Example:
const { data, dataState } = useQuery<TData>(query); if (dataState === "empty") { expectTypeOf(data).toEqualTypeOf<undefined>(); } if (dataState === "partial") { expectTypeOf(data).toEqualTypeOf<DeepPartial<TData>>(); } if (dataState === "streaming") { expectTypeOf(data).toEqualTypeOf<TData>(); } if (dataState === "complete") { expectTypeOf(data).toEqualTypeOf<TData>(); }