mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-09 23:16:51 +02:00
♻️ Create backend package (#643)
This commit is contained in:
parent
7fc08c6736
commit
05fe2edaea
68 changed files with 476 additions and 391 deletions
52
packages/backend/next/trpc/client.ts
Normal file
52
packages/backend/next/trpc/client.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
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>({
|
||||
unstable_overrides: {
|
||||
useMutation: {
|
||||
async onSuccess(opts) {
|
||||
/**
|
||||
* @note that order here matters:
|
||||
* The order here allows route changes in `onSuccess` without
|
||||
* having a flash of content change whilst redirecting.
|
||||
**/
|
||||
await opts.originalFn();
|
||||
if (!opts.meta?.doNotInvalidate) {
|
||||
await opts.queryClient.invalidateQueries();
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
config() {
|
||||
return {
|
||||
links: [
|
||||
httpBatchLink({
|
||||
url: `/api/trpc`,
|
||||
}),
|
||||
],
|
||||
transformer: superjson,
|
||||
queryClientConfig: {
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
cacheTime: Infinity,
|
||||
},
|
||||
},
|
||||
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,
|
||||
});
|
12
packages/backend/next/trpc/server.ts
Normal file
12
packages/backend/next/trpc/server.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import * as trpcNext from "@trpc/server/adapters/next";
|
||||
|
||||
import { createContext } from "../../trpc/context";
|
||||
import { appRouter } from "../../trpc/routers";
|
||||
import { withSessionRoute } from "../session";
|
||||
|
||||
export const trpcNextApiHandler = withSessionRoute(
|
||||
trpcNext.createNextApiHandler({
|
||||
router: appRouter,
|
||||
createContext,
|
||||
}),
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue