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.

fix(svelte): Move handler from mutationStore to subscriptionStore (#3078)

authored by

Phil Pluckthun and committed by
GitHub
f6b39ab4 8b1d1641

+33 -26
+5
.changeset/many-cats-travel.md
··· 1 + --- 2 + '@urql/svelte': major 3 + --- 4 + 5 + Move `handler`, which combines subscription events, from `mutationStore` to `subscriptionStore`. It’s accidentally been defined and implemented on the wrong store and was meant to be on `subscriptionStore`.
+9 -18
packages/svelte-urql/src/mutationStore.ts
··· 15 15 initialResult, 16 16 } from './common'; 17 17 18 - export type SubscriptionHandler<T, R> = (prev: R | undefined, data: T) => R; 19 - 20 18 export type MutationArgs< 21 19 Data = any, 22 20 Variables extends AnyVariables = AnyVariables ··· 27 25 28 26 export function mutationStore< 29 27 Data = any, 30 - Result = Data, 31 28 Variables extends AnyVariables = AnyVariables 32 - >( 33 - args: MutationArgs<Data, Variables>, 34 - handler?: SubscriptionHandler<Data, Result> 35 - ): OperationResultStore<Result, Variables> { 29 + >(args: MutationArgs<Data, Variables>): OperationResultStore<Data, Variables> { 36 30 const request = createRequest(args.query, args.variables as Variables); 37 31 const operation = args.client.createRequestOperation( 38 32 'mutation', 39 33 request, 40 34 args.context 41 35 ); 42 - const initialState: OperationResultState<Result, Variables> = { 36 + const initialState: OperationResultState<Data, Variables> = { 43 37 ...initialResult, 44 38 operation, 45 39 fetching: true, ··· 58 52 extensions, 59 53 })) 60 54 ), 61 - scan((result: OperationResultState<Result, Variables>, partial: any) => { 62 - // If a handler has been passed, it's used to merge new data in 63 - const data = 64 - partial.data !== undefined 65 - ? typeof handler === 'function' 66 - ? handler(result.data, partial.data) 67 - : partial.data 68 - : result.data; 69 - return { ...result, ...partial, data }; 70 - }, initialState), 55 + scan( 56 + (result: OperationResultState<Data, Variables>, partial) => ({ 57 + ...result, 58 + ...partial, 59 + }), 60 + initialState 61 + ), 71 62 subscribe(result => { 72 63 result$.set(result); 73 64 })
+19 -8
packages/svelte-urql/src/subscriptionStore.ts
··· 29 29 fromStore, 30 30 } from './common'; 31 31 32 + export type SubscriptionHandler<T, R> = (prev: R | undefined, data: T) => R; 33 + 32 34 export type SubscriptionArgs< 33 35 Data = any, 34 36 Variables extends AnyVariables = AnyVariables ··· 40 42 41 43 export function subscriptionStore< 42 44 Data, 45 + Result = Data, 43 46 Variables extends AnyVariables = AnyVariables 44 47 >( 45 - args: SubscriptionArgs<Data, Variables> 46 - ): OperationResultStore<Data, Variables> & Pausable { 48 + args: SubscriptionArgs<Data, Variables>, 49 + handler?: SubscriptionHandler<Data, Result> 50 + ): OperationResultStore<Result, Variables> & Pausable { 47 51 const request = createRequest(args.query, args.variables as Variables); 48 52 49 53 const operation = args.client.createRequestOperation( ··· 51 55 request, 52 56 args.context 53 57 ); 54 - const initialState: OperationResultState<Data, Variables> = { 58 + const initialState: OperationResultState<Result, Variables> = { 55 59 ...initialResult, 56 60 operation, 61 + fetching: true, 57 62 }; 58 63 const result$ = writable(initialState, () => { 59 64 return subscription.unsubscribe; ··· 85 90 ]); 86 91 } 87 92 ), 88 - scan( 89 - (result: OperationResultState<Data, Variables>, partial) => ({ 93 + scan((result: OperationResultState<Result, Variables>, partial) => { 94 + const data = 95 + partial.data !== undefined 96 + ? typeof handler === 'function' 97 + ? handler(result.data, partial.data) 98 + : partial.data 99 + : result.data; 100 + return { 90 101 ...result, 91 102 ...partial, 92 - }), 93 - initialState 94 - ), 103 + data, 104 + } as OperationResultState<Result, Variables>; 105 + }, initialState), 95 106 subscribe(result => { 96 107 result$.set(result); 97 108 })