Skip to content

Commit 6651650

Browse files
committed
fix: refresh force fetch
1 parent 18ae2b9 commit 6651650

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

packages/playground/app/pages/todo/index.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" setup>
22
const store = useStore()
33
4-
const { data: todos } = await store.Todo.queryMany()
4+
const { data: todos, refresh } = await store.Todo.queryMany()
55
66
const createTodo = store.Todo.createForm()
77
const createInput = useTemplateRef('input')
@@ -40,6 +40,12 @@ createTodo.$onSuccess(() => {
4040
:loading="createTodo.$loading"
4141
:disabled="!createTodo.$valid"
4242
/>
43+
44+
<UButton
45+
icon="lucide:refresh-cw"
46+
class="px-3"
47+
@click="refresh()"
48+
/>
4349
</UButtonGroup>
4450
</UForm>
4551

packages/vue/src/query.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function createQuery<
8383
_result: result,
8484
}
8585

86-
async function load() {
86+
async function load(force: boolean = false) {
8787
if (!isDisabled()) {
8888
loading.value = true
8989
error.value = null
@@ -93,13 +93,17 @@ export function createQuery<
9393
fetchPolicy = store.$getFetchPolicy(getOptions()?.fetchPolicy)
9494

9595
// If fetchPolicy is `cache-and-fetch`, fetch in parallel
96-
if (fetchPolicy === 'cache-and-fetch') {
96+
if (!force && fetchPolicy === 'cache-and-fetch') {
9797
fetchMethod({
9898
...finalOptions,
9999
fetchPolicy: 'fetch-only',
100100
} as FindOptions<TModel, TModelDefaults, TModelList> as any, meta.value)
101101
}
102102

103+
if (force) {
104+
finalOptions.fetchPolicy = 'fetch-only'
105+
}
106+
103107
result.value = await fetchMethod(finalOptions, meta.value)
104108
}
105109
catch (e: any) {
@@ -126,7 +130,7 @@ export function createQuery<
126130

127131
function refresh() {
128132
if (!loading.value) {
129-
promise = load() as HybridPromise<VueQueryReturn<TModel, TModelDefaults, TModelList, TResult>>
133+
promise = load(true) as HybridPromise<VueQueryReturn<TModel, TModelDefaults, TModelList, TResult>>
130134
Object.assign(promise, returnObject)
131135
}
132136
return promise

0 commit comments

Comments
 (0)