SudoerWithAnOpinion
SudoerWithAnOpinion
TtRPC
Created by SudoerWithAnOpinion on 8/31/2023 in #❓-help
Transformers not transforming data (trpc-sveltekit)
I'm having some trouble getting superjson to do its magic with tRPC & SvelteKit. I have a client.ts file that looks like this:
import superjson from 'superjson';
import { type TRPCClientInit, createTRPCClient } from 'trpc-sveltekit';
import type { Router } from '$lib/trpc/router';
let browserClient: ReturnType<typeof createTRPCClient<Router>>;
export function trpc(init?: TRPCClientInit) {
const isBrowser = typeof window !== 'undefined';
if (isBrowser && browserClient) return browserClient;
const client = createTRPCClient<Router>({ init, transformer: superjson });
if (isBrowser) browserClient = client;
return client;
}
import superjson from 'superjson';
import { type TRPCClientInit, createTRPCClient } from 'trpc-sveltekit';
import type { Router } from '$lib/trpc/router';
let browserClient: ReturnType<typeof createTRPCClient<Router>>;
export function trpc(init?: TRPCClientInit) {
const isBrowser = typeof window !== 'undefined';
if (isBrowser && browserClient) return browserClient;
const client = createTRPCClient<Router>({ init, transformer: superjson });
if (isBrowser) browserClient = client;
return client;
}
And a t.ts file that looks like this:
import { initTRPC } from '@trpc/server';
import superjson from 'superjson';
import type { Context } from '$lib/trpc/context';
export const t = initTRPC.context<Context>().create({
transformer: superjson
});
import { initTRPC } from '@trpc/server';
import superjson from 'superjson';
import type { Context } from '$lib/trpc/context';
export const t = initTRPC.context<Context>().create({
transformer: superjson
});
Despite including the transformer in both of these, I do not see data being transformed. Am I missing a place to add the transform function?
3 replies