Skip to content

Commit 5cc76f1

Browse files
committed
fix: update meta with fetch-and-cache
1 parent edd226b commit 5cc76f1

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

packages/vue/src/query.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,17 @@ export function createQuery<
458458
if (!forceFetch && fetchPolicy === 'cache-and-fetch') {
459459
shouldHandleQueryTracking = false
460460
const newQueryTracking2 = queryTracking?.createTrackingObject()
461+
462+
const fetchMeta: CustomHookMeta = {
463+
...meta.value,
464+
$queryTracking: queryTrackingEnabled ? newQueryTracking2 : undefined,
465+
}
466+
461467
fetchMethod({
462468
...finalOptions,
463469
fetchPolicy: 'fetch-only',
464-
} as FindOptions<TCollection, TCollectionDefaults, TSchema> as any, {
465-
...meta.value,
466-
$queryTracking: queryTrackingEnabled ? newQueryTracking2 : undefined,
467-
}).then(async (backgroundResult) => {
470+
} as FindOptions<TCollection, TCollectionDefaults, TSchema> as any, fetchMeta).then(async (backgroundResult) => {
471+
meta.value = fetchMeta
468472
const { valid } = await setPageResult(page, savedPageRequestId, backgroundResult)
469473
if (valid && queryTracking && newQueryTracking2) {
470474
queryTracking.handleQueryTracking(page.id, newQueryTracking2, undefined, finalOptions.include, page.main)

packages/vue/test/query.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,34 @@ describe('query', () => {
226226
})
227227
})
228228

229+
describe('cache-and-fetch', () => {
230+
it('should update the query meta', async () => {
231+
const store = await createStore({
232+
schema: [
233+
{
234+
name: 'messages',
235+
},
236+
],
237+
plugins: [],
238+
})
239+
240+
store.$hooks.hook('fetchMany', ({ meta, setResult }) => {
241+
const anyMeta = meta as any
242+
anyMeta.meow = 'waf'
243+
setResult([{ id: '1', text: 'hello' }])
244+
})
245+
246+
const query = await store.messages.query(q => q.many({
247+
fetchPolicy: 'cache-and-fetch',
248+
meta: { meow: 'meow' } as any,
249+
}))
250+
251+
await until(() => query.data.value.length).toBe(1)
252+
253+
expect((query.meta.value as any).meow).toBe('waf')
254+
})
255+
})
256+
229257
it('should handle fetch errors', async () => {
230258
const store = await createStore({
231259
schema: [

0 commit comments

Comments
 (0)