Skip to content

Commit

Permalink
fix(tanstack): incorrect vue-query options typing for vue-query v5
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 committed Jul 9, 2024
1 parent ac2b291 commit 74575fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions packages/plugins/tanstack-query/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ function makeBaseImports(target: TargetFramework, version: TanStackVersion) {
return [
`import type { UseMutationOptions, UseQueryOptions, UseInfiniteQueryOptions, InfiniteData } from '@tanstack/vue-query';`,
`import { getHooksContext } from '${runtimeImportBase}/${target}';`,
`import type { MaybeRefOrGetter, ComputedRef } from 'vue';`,
`import type { MaybeRefOrGetter, ComputedRef, UnwrapRef } from 'vue';`,
...shared,
];
}
Expand Down Expand Up @@ -674,7 +674,9 @@ function makeQueryOptions(
.with('vue', () => {
const baseOption = infinite
? `Omit<UseInfiniteQueryOptions<${returnType}, TError, InfiniteData<${dataType}>>, 'queryKey' | 'initialPageParam'>`
: `Omit<UseQueryOptions<${returnType}, TError, ${dataType}>, 'queryKey'>`;
: version === 'v4'
? `Omit<UseQueryOptions<${returnType}, TError, ${dataType}>, 'queryKey'>`
: `Omit<UnwrapRef<UseQueryOptions<${returnType}, TError, ${dataType}>>, 'queryKey'>`;
return `MaybeRefOrGetter<${baseOption}> | ComputedRef<${baseOption}>`;
})
.with('svelte', () =>
Expand Down
12 changes: 6 additions & 6 deletions packages/plugins/tanstack-query/tests/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ model Foo {
import { useFindFirstpost_Item, useInfiniteFindManypost_Item, useCreatepost_Item } from './hooks';
function query() {
const { data } = useFindFirstpost_Item({include: { author: true }});
const { data } = useFindFirstpost_Item({include: { author: true }}, { enabled: true, optimisticUpdate: false });
console.log(data?.viewCount);
console.log(data?.author?.email);
}
function infiniteQuery() {
const { data, fetchNextPage, hasNextPage } = useInfiniteFindManypost_Item();
useInfiniteFindManypost_Item({ where: { published: true } });
useInfiniteFindManypost_Item(undefined, { getNextPageParam: () => null });
useInfiniteFindManypost_Item(undefined, { enabled: true, getNextPageParam: () => null });
console.log(data?.pages[0][0].published);
console.log(data?.pageParams[0]);
}
Expand Down Expand Up @@ -143,14 +143,14 @@ ${sharedModel}
import { useFindFirstpost_Item, useInfiniteFindManypost_Item, useCreatepost_Item } from './hooks';
function query() {
const { data } = useFindFirstpost_Item({include: { author: true }});
const { data } = useFindFirstpost_Item({include: { author: true }}, { enabled: true, optimisticUpdate: false });
console.log(data.value?.viewCount);
console.log(data.value?.author?.email);
}
function infiniteQuery() {
const { data, fetchNextPage, hasNextPage } = useInfiniteFindManypost_Item();
useInfiniteFindManypost_Item({ where: { published: true } });
useInfiniteFindManypost_Item({ where: { published: true } }, { enabled: true, getNextPageParam: () => null });
useInfiniteFindManypost_Item(undefined, { getNextPageParam: () => null });
console.log(data.value?.pages[0][0].published);
console.log(data.value?.pageParams[0]);
Expand Down Expand Up @@ -217,15 +217,15 @@ ${sharedModel}
import { useFindFirstpost_Item, useInfiniteFindManypost_Item, useCreatepost_Item } from './hooks';
function query() {
const { data } = get(useFindFirstpost_Item({include: { author: true }}));
const { data } = get(useFindFirstpost_Item({include: { author: true }}, { enabled: true, optimisticUpdate: false }));
console.log(data?.viewCount);
console.log(data?.author?.email);
}
function infiniteQuery() {
const { data, fetchNextPage, hasNextPage } = get(useInfiniteFindManypost_Item());
useInfiniteFindManypost_Item({ where: { published: true } });
useInfiniteFindManypost_Item(undefined, { getNextPageParam: () => null });
useInfiniteFindManypost_Item(undefined, { enabled: true, getNextPageParam: () => null });
console.log(data?.pages[0][0].published);
console.log(data?.pageParams[0]);
}
Expand Down

0 comments on commit 74575fd

Please sign in to comment.