diff --git a/packages/plugins/tanstack-query/src/runtime-v5/svelte.ts b/packages/plugins/tanstack-query/src/runtime-v5/svelte.ts index 0ff05c1f0..2c554aec9 100644 --- a/packages/plugins/tanstack-query/src/runtime-v5/svelte.ts +++ b/packages/plugins/tanstack-query/src/runtime-v5/svelte.ts @@ -91,7 +91,7 @@ export function useModelQuery( ...options, }; } - return createQuery(mergedOpt); + return createQuery(mergedOpt); } /** diff --git a/packages/plugins/tanstack-query/tests/plugin.test.ts b/packages/plugins/tanstack-query/tests/plugin.test.ts index d5f5c7d3a..88c8fd7e8 100644 --- a/packages/plugins/tanstack-query/tests/plugin.test.ts +++ b/packages/plugins/tanstack-query/tests/plugin.test.ts @@ -18,7 +18,7 @@ describe('Tanstack Query Plugin Tests', () => { const sharedModel = ` model User { - id String @id + id String @id @default(cuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt email String @unique @@ -32,7 +32,7 @@ enum role { } model post_Item { - id String @id + id String @id @default(cuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt title String @@ -51,13 +51,28 @@ model Foo { const reactAppSource = { name: 'main.ts', content: ` - import { useInfiniteFindManypost_Item } from './hooks'; + import { useFindFirstpost_Item, useInfiniteFindManypost_Item, useCreatepost_Item } from './hooks'; - const { data, fetchNextPage, hasNextPage } = useInfiniteFindManypost_Item(); - useInfiniteFindManypost_Item({ where: { published: true } }); - useInfiniteFindManypost_Item(undefined, { getNextPageParam: () => null }); - console.log(data?.pages[0][0].published); - console.log(data?.pageParams[0]); + function query() { + const { data } = useFindFirstpost_Item({include: { author: true }}); + 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 }); + console.log(data?.pages[0][0].published); + console.log(data?.pageParams[0]); + } + + async function mutation() { + const { mutateAsync } = useCreatepost_Item(); + const data = await mutateAsync({ data: { title: 'hello' }, include: { author: true } }); + console.log(data?.viewCount); + console.log(data?.author?.email); + } `, }; @@ -108,11 +123,13 @@ ${sharedModel} content: ` import { useSuspenseInfiniteFindManypost_Item } from './hooks'; - const { data, fetchNextPage, hasNextPage } = useSuspenseInfiniteFindManypost_Item(); - useSuspenseInfiniteFindManypost_Item({ where: { published: true } }); - useSuspenseInfiniteFindManypost_Item(undefined, { getNextPageParam: () => null }); - console.log(data?.pages[0][0].published); - console.log(data?.pageParams[0]); + function suspenseInfiniteQuery() { + const { data, fetchNextPage, hasNextPage } = useSuspenseInfiniteFindManypost_Item(); + useSuspenseInfiniteFindManypost_Item({ where: { published: true } }); + useSuspenseInfiniteFindManypost_Item(undefined, { getNextPageParam: () => null }); + console.log(data?.pages[0][0].published); + console.log(data?.pageParams[0]); + } `, }, ], @@ -123,13 +140,28 @@ ${sharedModel} const vueAppSource = { name: 'main.ts', content: ` - import { useInfiniteFindManypost_Item } from './hooks'; + import { useFindFirstpost_Item, useInfiniteFindManypost_Item, useCreatepost_Item } from './hooks'; + + function query() { + const { data } = useFindFirstpost_Item({include: { author: true }}); + console.log(data.value?.viewCount); + console.log(data.value?.author?.email); + } - const { data, fetchNextPage, hasNextPage } = useInfiniteFindManypost_Item(); - useInfiniteFindManypost_Item({ where: { published: true } }); - useInfiniteFindManypost_Item(undefined, { getNextPageParam: () => null }); - console.log(data.value?.pages[0][0].published); - console.log(data.value?.pageParams[0]); + function infiniteQuery() { + const { data, fetchNextPage, hasNextPage } = useInfiniteFindManypost_Item(); + useInfiniteFindManypost_Item({ where: { published: true } }); + useInfiniteFindManypost_Item(undefined, { getNextPageParam: () => null }); + console.log(data.value?.pages[0][0].published); + console.log(data.value?.pageParams[0]); + } + + async function mutation() { + const { mutateAsync } = useCreatepost_Item(); + const data = await mutateAsync({ data: { title: 'hello' }, include: { author: true } }); + console.log(data?.viewCount); + console.log(data?.author?.email); + } `, }; @@ -182,13 +214,28 @@ ${sharedModel} name: 'main.ts', content: ` import { get } from 'svelte/store'; - import { useInfiniteFindManypost_Item } from './hooks'; + import { useFindFirstpost_Item, useInfiniteFindManypost_Item, useCreatepost_Item } from './hooks'; + + function query() { + const { data } = get(useFindFirstpost_Item({include: { author: true }})); + 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 }); + console.log(data?.pages[0][0].published); + console.log(data?.pageParams[0]); + } - const { data, fetchNextPage, hasNextPage } = get(useInfiniteFindManypost_Item()); - useInfiniteFindManypost_Item({ where: { published: true } }); - useInfiniteFindManypost_Item(undefined, { getNextPageParam: () => null }); - console.log(data?.pages[0][0].published); - console.log(data?.pageParams[0]); + async function mutation() { + const { mutateAsync } = get(useCreatepost_Item()); + const data = await mutateAsync({ data: { title: 'hello' }, include: { author: true } }); + console.log(data?.viewCount); + console.log(data?.author?.email); + } `, };