add the tRPC hello world example

Signed-off-by: Oleg S <97077423+RobotSail@users.noreply.github.com>
This commit is contained in:
Oleg S
2023-01-31 17:06:16 -05:00
parent a2194b2a4d
commit a16f81df08
@@ -0,0 +1,25 @@
apiVersion: backstage.io/v1alpha1
kind: API
metadata:
name: hello-world-trpc
description: Hello World example for tRPC
spec:
type: trpc
lifecycle: experimental
owner: team-c
definition: |
import { z } from 'zod';
import { publicProcedure, router } from '../trpc';
export const apiRouter = router({
version: publicProcedure.query(() => {
return { version: '0.42.0' };
}),
hello: publicProcedure
.input(z.object({ username: z.string().nullish() }).nullish())
.query(({ input, ctx }) => {
return {
text: `hello ${input?.username ?? ctx.user?.name ?? 'world'}`,
};
}),
});