@@ -119,7 +119,8 @@ export function queryStore<
119119 Variables extends AnyVariables = AnyVariables ,
120120> (
121121 args : QueryArgs < Data , Variables >
122- ) : OperationResultStore < Data , Variables > & Pausable {
122+ ) : OperationResultStore < Data , Variables > &
123+ Pausable & { reexecute : ( context : Partial < OperationContext > ) => void } {
123124 const request = createRequest ( args . query , args . variables as Variables ) ;
124125
125126 const context : Partial < OperationContext > = {
@@ -132,6 +133,9 @@ export function queryStore<
132133 request ,
133134 context
134135 ) ;
136+
137+ const operation$ = writable ( operation ) ;
138+
135139 const initialState : OperationResultState < Data , Variables > = {
136140 ...initialResult ,
137141 operation,
@@ -148,21 +152,26 @@ export function queryStore<
148152 return never as any ;
149153 }
150154
151- return concat < Partial < OperationResultState < Data , Variables > > > ( [
152- fromValue ( { fetching : true , stale : false } ) ,
153- pipe (
154- args . client . executeRequestOperation ( operation ) ,
155- map ( ( { stale, data, error, extensions, operation } ) => ( {
156- fetching : false ,
157- stale : ! ! stale ,
158- data,
159- error,
160- operation,
161- extensions,
162- } ) )
163- ) ,
164- fromValue ( { fetching : false } ) ,
165- ] ) ;
155+ return pipe (
156+ fromStore ( operation$ ) ,
157+ switchMap ( operation => {
158+ return concat < Partial < OperationResultState < Data , Variables > > > ( [
159+ fromValue ( { fetching : true , stale : false } ) ,
160+ pipe (
161+ args . client . executeRequestOperation ( operation ) ,
162+ map ( ( { stale, data, error, extensions, operation } ) => ( {
163+ fetching : false ,
164+ stale : ! ! stale ,
165+ data,
166+ error,
167+ operation,
168+ extensions,
169+ } ) )
170+ ) ,
171+ fromValue ( { fetching : false } ) ,
172+ ] ) ;
173+ } )
174+ ) ;
166175 }
167176 ) ,
168177 scan (
@@ -178,10 +187,22 @@ export function queryStore<
178187 ) . unsubscribe ;
179188 } ) ;
180189
190+ const reexecute = ( context : Partial < OperationContext > ) => {
191+ const newContext = { ...context , ...args . context } ;
192+ const operation = args . client . createRequestOperation (
193+ 'query' ,
194+ request ,
195+ newContext
196+ ) ;
197+ isPaused$ . set ( false ) ;
198+ operation$ . set ( operation ) ;
199+ } ;
200+
181201 return {
182202 ...derived ( result$ , ( result , set ) => {
183203 set ( result ) ;
184204 } ) ,
185205 ...createPausable ( isPaused$ ) ,
206+ reexecute,
186207 } ;
187208}
0 commit comments