vishalbalaji / trpc-svelte-query-adapter

A simple adapter to use `@tanstack/svelte-query` with trpc, similar to `@trpc/react-query`.
71 stars 6 forks source link

using on server load/ api routes #12

Closed ghost closed 1 year ago

ghost commented 1 year ago

how to get the original trpc client to get data on the server load/actions or inside +server.ts files?

vishalbalaji commented 1 year ago

You can use trpc().createContext().client to grab the original client.

Although, you would not be able to initialize a client in a +server.ts or +page.server.ts, since QueryClient is not available on the server. In this case, you might want to import your trpc router directly and call router.createCaller() to create a tRPC caller on the server.

vishalbalaji commented 1 year ago

@pukarsharma112, is the issue resolved? If so, can you please close it?

vishalbalaji commented 1 year ago

Closing due to inactivity.

ghost commented 1 year ago

i was able to use createContext() on +page.server.ts and +server.ts by passing queryClient as empty object ( although typescript shows error ) but i got my problem solved atleast so this issue can be closed :-)