Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

(core) - Prevent stale results from promisified sources (#1709)

authored by

Phil Pluckthun and committed by
GitHub
eed49061 64312999

+18 -5
+5
.changeset/smooth-hounds-battle.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Prevent stale results from being emitted by promisified query sources, e.g. `client.query(...).toPromise()` yielding a partial result with `stale: true` set. Instead, `.toPromise()` will now filter out stale results.
+13 -5
packages/core/src/utils/streamUtils.ts
··· 1 - import { Source, pipe, toPromise, take } from 'wonka'; 1 + import { Source, pipe, toPromise, filter, take } from 'wonka'; 2 + import { OperationResult, PromisifiedSource } from '../types'; 2 3 3 - import { PromisifiedSource } from '../types'; 4 + export function withPromise<T extends OperationResult>( 5 + source$: Source<T> 6 + ): PromisifiedSource<T> { 7 + (source$ as PromisifiedSource<T>).toPromise = () => { 8 + return pipe( 9 + source$, 10 + filter(result => !result.stale), 11 + take(1), 12 + toPromise 13 + ); 14 + }; 4 15 5 - export function withPromise<T>(source$: Source<T>): PromisifiedSource<T> { 6 - (source$ as PromisifiedSource<T>).toPromise = () => 7 - pipe(source$, take(1), toPromise); 8 16 return source$ as PromisifiedSource<T>; 9 17 }