♻️ Move trpc client code to app (#906)

This commit is contained in:
Luke Vella 2023-10-20 15:46:02 +01:00 committed by GitHub
parent 502f2a7a43
commit 5be17fd249
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 133 additions and 124 deletions

View file

@ -1,40 +0,0 @@
import { MutationCache } from "@tanstack/react-query";
import { httpBatchLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import toast from "react-hot-toast";
import superjson from "superjson";
import { AppRouter } from "../../trpc/routers";
export * from "../../trpc/types";
export const trpc = createTRPCNext<AppRouter>({
config() {
return {
links: [
httpBatchLink({
url: `/api/trpc`,
}),
],
transformer: superjson,
queryClientConfig: {
defaultOptions: {
queries: {
retry: false,
networkMode: "always",
cacheTime: Infinity,
staleTime: 1000 * 60,
},
},
mutationCache: new MutationCache({
onError: () => {
toast.error(
"Uh oh! Something went wrong. The issue has been logged and we'll fix it as soon as possible. Please try again later.",
);
},
}),
},
};
},
ssr: false,
});

View file

@ -1,27 +0,0 @@
import { EmailClient } from "@rallly/emails";
import * as trpcNext from "@trpc/server/adapters/next";
import { appRouter } from "../../trpc/routers";
export interface TRPCContext {
user: { id: string; isGuest: boolean };
emailClient: EmailClient;
isSelfHosted: boolean;
isEmailBlocked?: (email: string) => boolean;
/**
* Takes a relative path and returns an absolute URL to the app
* @param path
* @returns absolute URL
*/
absoluteUrl: (path?: string) => string;
shortUrl: (path?: string) => string;
}
export const trpcNextApiHandler = (context: TRPCContext) => {
return trpcNext.createNextApiHandler({
router: appRouter,
createContext: async () => {
return context;
},
});
};