scrubdaddy
scrubdaddy
TtRPC
Created by scrubdaddy on 7/20/2024 in #❓-help
Compiling Frontend
is it possible to just get it to ignore this, because it only impacts CI?
4 replies
TtRPC
Created by scrubdaddy on 7/17/2024 in #❓-help
Types not being shared with the frontend
switching to createTRPCProxyClient solved this problem
8 replies
TtRPC
Created by scrubdaddy on 7/17/2024 in #❓-help
Types not being shared with the frontend
however when I import the AppRouter type on the frontend, it appears to be a blank version with no routes
8 replies
TtRPC
Created by scrubdaddy on 7/17/2024 in #❓-help
Types not being shared with the frontend
No description
8 replies
TtRPC
Created by scrubdaddy on 7/17/2024 in #❓-help
Types not being shared with the frontend
could this have something to do with rootdir?
8 replies
TtRPC
Created by scrubdaddy on 7/17/2024 in #❓-help
Types not being shared with the frontend
here is the code that is producing the error:
import type { AppRouter } from "../../../lambda/api-handler/src/index";
import { createTRPCClient, httpBatchLink } from "@trpc/client";
const client = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: AWS_API_GATEWAY_URL + "/api",
}),
],
});
const q = await client.greet.query({ name: "Erik" });
import type { AppRouter } from "../../../lambda/api-handler/src/index";
import { createTRPCClient, httpBatchLink } from "@trpc/client";
const client = createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: AWS_API_GATEWAY_URL + "/api",
}),
],
});
const q = await client.greet.query({ name: "Erik" });
the backend code is directly copied from one of the examples:
import { initTRPC } from "@trpc/server";
import type { CreateAWSLambdaContextOptions } from "@trpc/server/adapters/aws-lambda";
import { awsLambdaRequestHandler } from "@trpc/server/adapters/aws-lambda";
import type { APIGatewayProxyEvent } from "aws-lambda";
import { z } from "zod";

function createContext({
event,
context,
}: CreateAWSLambdaContextOptions<APIGatewayProxyEvent>) {
return {
event: event,
apiVersion: (event as { version?: string }).version ?? "1.0",
user: event.headers["x-user"],
};
}
type Context = Awaited<ReturnType<typeof createContext>>;

const t = initTRPC.context<Context>().create();

const publicProcedure = t.procedure;
const router = t.router;

const appRouter = router({
greet: publicProcedure
.input(z.object({ name: z.string() }))
.query(({ input, ctx }) => {
return `Greetings, ${input.name}. x-user?: ${ctx.user}.`;
}),
});

export type AppRouter = typeof appRouter;

export const handler = awsLambdaRequestHandler({
router: appRouter,
createContext,
});
import { initTRPC } from "@trpc/server";
import type { CreateAWSLambdaContextOptions } from "@trpc/server/adapters/aws-lambda";
import { awsLambdaRequestHandler } from "@trpc/server/adapters/aws-lambda";
import type { APIGatewayProxyEvent } from "aws-lambda";
import { z } from "zod";

function createContext({
event,
context,
}: CreateAWSLambdaContextOptions<APIGatewayProxyEvent>) {
return {
event: event,
apiVersion: (event as { version?: string }).version ?? "1.0",
user: event.headers["x-user"],
};
}
type Context = Awaited<ReturnType<typeof createContext>>;

const t = initTRPC.context<Context>().create();

const publicProcedure = t.procedure;
const router = t.router;

const appRouter = router({
greet: publicProcedure
.input(z.object({ name: z.string() }))
.query(({ input, ctx }) => {
return `Greetings, ${input.name}. x-user?: ${ctx.user}.`;
}),
});

export type AppRouter = typeof appRouter;

export const handler = awsLambdaRequestHandler({
router: appRouter,
createContext,
});
8 replies