You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repo contains the templates used by the webrpc-gen cli to code-generate
webrpc Typescript server and client code.
This generator, from a webrpc schema/design file will code-generate:
Client -- an isomorphic/universal Typescript client to speak to a webrpc server using the
provided schema. This client is compatible with any webrpc server language (ie. Go, nodejs, etc.).
As the client is isomorphic, means you can use this within a Web browser or use the client in a
server like nodejs -- both without needing any dependencies. I suggest to read the generated TS
output of the generated code, and you shall see, its nothing fancy, just the sort of thing you'd
write by hand.
Server -- a nodejs Typescript server handler. See examples.
Features
Query Keys for React Query / SWR
The generated client includes a queryKey property with type-safe query key generators for each endpoint. This makes it easy to use with popular data-fetching libraries:
import{useQuery}from'@tanstack/react-query'import{Example}from'./client.gen'constclient=newExample('https://localhost:3000',fetch)functionUserProfile({ userId }){const{ data }=useQuery({queryKey: client.queryKey.getUser({ userId }),queryFn: ({ signal })=>client.getUser({ userId },undefined,signal)})return<div>{data?.user.name}</div>}
The query keys follow the pattern [ServiceName, methodName, request?] and are fully type-safe with as const assertions.