tRPCttRPC
Powered by
🇵🇸 Prince Toast�
tRPC•3y ago•
1 reply
🇵🇸 Prince Toast

I can't mutate or query in SvelteKit

Environment: Node 20 with Yarn
I'm not getting any specific errors but I don't get the "mutate" or "query" methods with trpc client in SvelteKit. Here is the situation:
My API is written in Fastify. I'm using the Fastify adapter for tRPC. On the client, I get autocompletion for the routers (like user.createAccount or post.getAll) but I don't get the ability to mutate or query data.
// api.ts file in lib folder
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from '../../../backend/src/router';

export const api = createTRPCProxyClient<AppRouter>({
    links: [
        httpBatchLink({
            url: 'http://localhost:5173/api',
            // You can pass any HTTP headers you wish here
            async headers() {
                return {
                    authorization: (localStorage.getItem('token')
                        ? localStorage.getItem('token')
                        : '') as string
                };
            }
        })
    ]
});
// api.ts file in lib folder
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from '../../../backend/src/router';

export const api = createTRPCProxyClient<AppRouter>({
    links: [
        httpBatchLink({
            url: 'http://localhost:5173/api',
            // You can pass any HTTP headers you wish here
            async headers() {
                return {
                    authorization: (localStorage.getItem('token')
                        ? localStorage.getItem('token')
                        : '') as string
                };
            }
        })
    ]
});
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Can't access mutate utils by createTRPCQueryUtils
Jay_OhhhJJay_Ohhh / ❓-help
2y ago
query and mutate promise on next
TuxerTTuxer / ❓-help
4y ago
[Typescript] Client query / mutate has any type
KhojoKKhojo / ❓-help
10mo ago