-
-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make useQuery refetch async #3434
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,7 +158,9 @@ export interface UseQueryState< | |
* }; | ||
* ``` | ||
*/ | ||
export type UseQueryExecute = (opts?: Partial<OperationContext>) => void; | ||
export type UseQueryExecute = ( | ||
opts?: Partial<OperationContext> | ||
) => Promise<unknown>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering whether this could turn into a breaking change, i.e. something complaining about not awaiting/... when doing |
||
|
||
/** Result tuple returned by the {@link useQuery} hook. | ||
* | ||
|
@@ -355,25 +357,30 @@ export function useQuery< | |
}, [cache, state[0], state[2][1]]); | ||
|
||
const executeQuery = React.useCallback( | ||
(opts?: Partial<OperationContext>) => { | ||
const context = { | ||
requestPolicy: args.requestPolicy, | ||
...args.context, | ||
...opts, | ||
}; | ||
(opts?: Partial<OperationContext>) => | ||
new Promise<void>(resolve => { | ||
const context = { | ||
requestPolicy: args.requestPolicy, | ||
...args.context, | ||
...opts, | ||
}; | ||
|
||
deferDispatch(setState, state => { | ||
const source = suspense | ||
? pipe( | ||
client.executeQuery(request, context), | ||
onPush(result => { | ||
cache.set(request.key, result); | ||
}) | ||
) | ||
: client.executeQuery(request, context); | ||
return [source, state[1], deps]; | ||
}); | ||
}, | ||
deferDispatch(setState, state => { | ||
const source = suspense | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also did |
||
? pipe( | ||
client.executeQuery(request, context), | ||
onPush(result => { | ||
cache.set(request.key, result); | ||
resolve(); | ||
}) | ||
) | ||
: pipe(client.executeQuery(request, context), result => { | ||
resolve(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in a So what we could do is create the |
||
return result; | ||
}); | ||
return [source, state[1], deps]; | ||
}); | ||
}), | ||
[ | ||
client, | ||
cache, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this returns a promise now, tsc complained