Luka
Luka
TtRPC
Created by Luka on 7/12/2024 in #❓-help
failed to parse json
next auth was filtering the endpoint
5 replies
TtRPC
Created by Luka on 7/12/2024 in #❓-help
failed to parse json
nvm got it
5 replies
TtRPC
Created by Luka on 11/29/2023 in #❓-help
React Query client and caller client under one object
why use createTRPCProxyClient over just appRouter.createCaller({})
5 replies
TtRPC
Created by Luka on 11/11/2023 in #❓-help
Merging two clients into one
some merge function from trpc library could be cool for this, or a client for nextjs 13 that allows both simple queries for server components and react-query for client components
13 replies
TtRPC
Created by Luka on 11/11/2023 in #❓-help
Merging two clients into one
so theres really no way to merge the two clients and have the auto suggestions the way it is in the screenshot at the start.
13 replies
TtRPC
Created by Luka on 11/11/2023 in #❓-help
Merging two clients into one
if you do
export const api = mergeProxies(server, client);
export const api = mergeProxies(server, client);
you will get an error client[procedureType] is not a function
13 replies
TtRPC
Created by Luka on 11/11/2023 in #❓-help
Merging two clients into one
you will get error Cannot access cart.getCartItems on the server. You cannot dot into a client module from a server component. You can only pass the imported name through.
13 replies
TtRPC
Created by Luka on 11/11/2023 in #❓-help
Merging two clients into one
export const api = mergeProxies(client, server);
export const api = mergeProxies(client, server);
like this
13 replies
TtRPC
Created by Luka on 11/11/2023 in #❓-help
Merging two clients into one
but the caveat is that when you get to your procedure/endpoint property the object that comes first when called in the function takes precedence.
13 replies
TtRPC
Created by Luka on 11/11/2023 in #❓-help
Merging two clients into one
small update if anyone is gets interested in this in the future. you can merge the two proxies using this function
function mergeProxies<T, U>(client: T, server: U): T & U {
const proxy = new Proxy(
{},
{
get(_, prop) {
return (client as any)[prop] || (server as any)[prop];
},
},
);
return proxy as T & U;
}
function mergeProxies<T, U>(client: T, server: U): T & U {
const proxy = new Proxy(
{},
{
get(_, prop) {
return (client as any)[prop] || (server as any)[prop];
},
},
);
return proxy as T & U;
}
13 replies
TtRPC
Created by Luka on 11/11/2023 in #❓-help
Merging two clients into one
you pretty much would have access to both clients under one trpc source
13 replies
TtRPC
Created by Luka on 11/11/2023 in #❓-help
Merging two clients into one
just wanted to have one api object, seemed like a better workflow
13 replies