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?
1 Reply
SudoerWithAnOpinion
SudoerWithAnOpinionOP15mo ago
For added contextm this is one of my routers...
import { Punch } from '$lib/models'; // Sequelize Model
import { auth } from '$lib/trpc/middleware/auth';
import { t } from '$lib/trpc/t';
const router = t.router({
lastPunch: t.procedure.use(auth).query(async ({ ctx }) => {
return Punch.findOne({
where: { user_id: ctx.session?.user.id }
}).then((result) => {
return result; // instance of Punch or NULL
});
}),
});
import { Punch } from '$lib/models'; // Sequelize Model
import { auth } from '$lib/trpc/middleware/auth';
import { t } from '$lib/trpc/t';
const router = t.router({
lastPunch: t.procedure.use(auth).query(async ({ ctx }) => {
return Punch.findOne({
where: { user_id: ctx.session?.user.id }
}).then((result) => {
return result; // instance of Punch or NULL
});
}),
});
I have changed from superJSON to trpc-transformer to no avail.