-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
createQueries
and createServerQueries
for svelte-query v5 …
…and add support for `combine` (#43) * feat: add support for `combine` for `createQueries` and `createServerQueries` * bump version
- Loading branch information
1 parent
8fc3a46
commit 03d590e
Showing
4 changed files
with
98 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.