Skip to content

Commit

Permalink
Update createQueries and createServerQueries for svelte-query v5 …
Browse files Browse the repository at this point in the history
…and add support for `combine` (#43)

* feat: add support for `combine` for `createQueries` and
`createServerQueries`

* bump version
  • Loading branch information
vishalbalaji authored Jul 10, 2024
1 parent 8fc3a46 commit 03d590e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 80 deletions.
19 changes: 5 additions & 14 deletions @app/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
<script lang="ts">
import { page } from '$app/stores';
import { trpc } from '$lib/trpc/client';
const api = trpc($page);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const query = api.greeting.createQuery();
export let data;
const queries = data.queries();
</script>

<!-- {#if $query.isPending} -->
<!-- Loading... -->
<!-- {:else if $query.isError} -->
<!-- Error: {$query.error.message} -->
<!-- {:else if $query.data} -->
<!-- {$query.data} -->
<!-- {/if} -->
<pre>
{JSON.stringify($queries, null, 2)}
</pre>
15 changes: 15 additions & 0 deletions @app/src/routes/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { trpc } from '$lib/trpc/client';

export async function load(event) {
const { queryClient } = await event.parent();
const api = trpc(event, queryClient);

return {
queries: await api.createServerQueries((t) => [t.greeting('foo'), t.greeting('bar')], {
combine: (results) => ({
foo: results.map(({ data }) => data),
pending: results.some(({ isPending }) => isPending)
})
})
}
}
2 changes: 1 addition & 1 deletion @lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trpc-svelte-query-adapter",
"version": "2.3.4",
"version": "2.3.5",
"description": "A simple adapter to use `@tanstack/svelte-query` with trpc, similar to `@trpc/react-query`.",
"keywords": [
"trpc",
Expand Down
Loading

0 comments on commit 03d590e

Please sign in to comment.