xdxd#5555 / hanya
xdxd#5555 / hanya
TtRPC
Created by xdxd#5555 / hanya on 8/17/2023 in #❓-help
Queries work but mutations do not
Odd bug I'm experiencing with TRPC + react-query + the koa adapter. I just set everything up per docs. I tried out a test query and a test mutation, both with very simple input validated by Zod. The query hits the backend route but the mutation never does - even if I change the inputs, etc. Does anyone have any idea where to look for the culprit here?
5 replies
TtRPC
Created by xdxd#5555 / hanya on 4/23/2023 in #❓-help
ECONNREFUSED with TRPC call on Vercel
13 replies
TtRPC
Created by xdxd#5555 / hanya on 4/19/2023 in #❓-help
Adding clerk auth object to createServerSideHelpers
So I followed clerk's docs for TRPC (https://clerk.com/docs/nextjs/trpc) and I added auth to the context object. This works great for most requests I've made, but I'm having trouble now that I'm trying to use getStaticProps and createServerSideHelpers. I slightly changed the AuthContext type so that auth can be undefined, which would make sense when the page is generated at build. But is there a way to get auth info in there, when the page gets regenerated later as a user visits? Or would I need to make any auth-related stuff part of the client code? Snippet:
export const getStaticProps: GetStaticProps = async (context) => {
const helpers = createServerSideHelpers({
router: appRouter,
ctx: { prisma, auth: undefined }, // would like to define auth if possible!
transformer: superjson,
});
...
export const getStaticProps: GetStaticProps = async (context) => {
const helpers = createServerSideHelpers({
router: appRouter,
ctx: { prisma, auth: undefined }, // would like to define auth if possible!
transformer: superjson,
});
...
4 replies
TtRPC
Created by xdxd#5555 / hanya on 4/19/2023 in #❓-help
Call retries were exceeded with ssg
I'm running a create-t3-app on Node 18. Has anyone seen errors trying to use SSG with TRPC and Prisma? I'm new to the T3 stack overall so I'm not sure if the error really comes down to Next, Prisma, or TRPC here. But when I try building with the code below, I'll run into Error: Call retries were exceeded, coming from, of all things, next/dist/compiled/jest-worker/index.js, which I thought was super weird. Not sure how this could be related to Jest. There are 1204 cats, so I'm trying to generate 1204 pages here, so maybe that's just too much? I noticed that if I add take: 10 to getStaticPaths, then I don't see this error anymore. But on the other hand, all I'm trying to do to generate each one is just a simple db query. TBH I would have this expected to scale to as many pages as I need to generate here.
export const getStaticProps: GetStaticProps = async (context) => {
const helpers = createServerSideHelpers({
router: appRouter,
ctx: { prisma, auth: {} },
transformer: superjson,
});

const catId = context.params?.catId;
if (typeof catId !== "string") {
// TODO: improve this behavior, maybe go to new page.
throw new Error("Missing params");
}

await helpers.cat.byId.prefetch({ catId });

return {
props: {
catId,
trpcState: helpers.dehydrate(),
},
};
};

export const getStaticPaths: GetStaticPaths = async () => {
const cats = await prisma.cat.findMany({
select: { id: true },
// take: 10,
});
const catIds = cats.map((cat) => ({ params: { catId: String(cat.id) } }));
console.log("CAT LENGTH", cats.length, catIds.length);
return {
paths: catIds,
fallback: "blocking",
};
};
export const getStaticProps: GetStaticProps = async (context) => {
const helpers = createServerSideHelpers({
router: appRouter,
ctx: { prisma, auth: {} },
transformer: superjson,
});

const catId = context.params?.catId;
if (typeof catId !== "string") {
// TODO: improve this behavior, maybe go to new page.
throw new Error("Missing params");
}

await helpers.cat.byId.prefetch({ catId });

return {
props: {
catId,
trpcState: helpers.dehydrate(),
},
};
};

export const getStaticPaths: GetStaticPaths = async () => {
const cats = await prisma.cat.findMany({
select: { id: true },
// take: 10,
});
const catIds = cats.map((cat) => ({ params: { catId: String(cat.id) } }));
console.log("CAT LENGTH", cats.length, catIds.length);
return {
paths: catIds,
fallback: "blocking",
};
};
The error:
error - Error: Call retries were exceeded
at ChildProcessWorker.initialize (/foo-t3-app/node_modules/next/dist/compiled/jest-worker/index.js:1:11661)
at ChildProcessWorker._onExit (/foo-t3-app/node_modules/next/dist/compiled/jest-worker/index.js:1:12599)
error - Error: Call retries were exceeded
at ChildProcessWorker.initialize (/foo-t3-app/node_modules/next/dist/compiled/jest-worker/index.js:1:11661)
at ChildProcessWorker._onExit (/foo-t3-app/node_modules/next/dist/compiled/jest-worker/index.js:1:12599)
3 replies