Comments (1)
- You should include
TRPCModule.forRoot
in your app module as shown in the example. - Take
init-trpc
and put it somewhere central. You shouldexport type Router = typeof appRouter
here (this is missing in the example but it is assumed you understand this, as it is the main requirement of tRPC that is covered in their great documentation.) - Write your router with procedures in
init-trpc
, in each procedure you can resolve any service class you wish that has the actual business logic you route to (as shown withctx.resolveNestDependency(AService)
). This particular step is why this adapter exists, to allow you to use nest's dependency injection in your routes. - At some point, you can start breaking out of
init-trpc
via providing a list of routes in each of your modules (eg. user/user.routes.ts), then importing them all back up to theinit-trpc
level where you actually create the router out of all of them (you can use tRPC.mergeRouters or nest them in namespaces, see tRPC docs). The main requirement of tRPC is that you combine all your routes into a router and export its type for your front-end to use. When you import the type of the router only, your front end does not include any server side code in the bundle, as typescript types get stripped. - If you are not familiar with the intricacies of modules and bundlers, I would recommend putting some very loud console.logs in your server code, to make sure they never show up anywhere in your client's runtime (in terminal, nor in the browser) so that you can be sure you're not baking in your database secrets or anything of the sort.
from trpc-nestjs-adapter.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trpc-nestjs-adapter.