macstr1k3r / trpc-nestjs-adapter Goto Github PK
View Code? Open in Web Editor NEWAn adapter, allowing you to use TRPC inside of Nest.JS
An adapter, allowing you to use TRPC inside of Nest.JS
Hi, thanks for the great adapter!
I'm trying it out but having issues resolving services that have a Prisma service injected into them (most of the services in the application), which is very similar to the example in the Nest docs: https://docs.nestjs.com/recipes/prisma#use-prisma-client-in-your-nestjs-services. I just get an infinite loading spinner when I try to access any of the trpc endpoints. It seems to work when I use a service in tRPC that doesn't have any injected dependencies.
Does anyone have any ideas why this isn't resolving? Is there any more information I can provide to help debug this? Would love to be able to use this properly!
EDIT: Tried nestjs-prisma too and this exhibits the same behavior. NodeJS ran out of memory after hitting the tRPC endpoint.
I have implemented NestJS
connection to tRPC
without your adapter, and found your solution looking for a way to authorize via context, but I see that you don't have it in your example either. Perhaps you have some ideas?
I, just like in your implementation, albeit in a different way, have access to services to call them in query
and mutation
, but I don't in createContext
.
I am wondering if there is a way to create custom decorators to route the procedures, i.e.
@Controller('api/cats')
export class CatsController {
@Mutation({ input: z.object({ name: z.string(), }).optional() })
createCat(@Input() input: { name: string }) {
// do stuff
}
@Query({ input: z.object({ id: z.string(), }).optional() })
getCat(@Input() input: { id: string }) {
// do stuff
}
}
What's your initial take? I can work on a PoC
Hi. I want to use this and try it out but i don't know how to use it exactly.. i see an example folder, so do i need to copy that whole folder including the /lib into my project? Or how does this work? I don't see how to run the example you have to see it working. Should I be able to?
(my use case is a monorepo with a single node_modules for front end and backend).
reproduce:
mkdir zz
cd zz
npm init
npm install trpc-nestjs-adapter @trpc/client @trpc/server
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: @trpc/[email protected]
npm ERR! node_modules/@trpc/server
npm ERR! @trpc/server@"" from the root project
npm ERR! peer @trpc/server@"10.11.0" from @trpc/[email protected]
npm ERR! node_modules/@trpc/client
npm ERR! @trpc/client@"" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! trpc-nestjs-adapter@"" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @trpc/[email protected]
npm ERR! node_modules/@trpc/server
npm ERR! peer @trpc/server@"~10.10.0" from [email protected]
npm ERR! node_modules/trpc-nestjs-adapter
npm ERR! trpc-nestjs-adapter@"" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/rk/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/rk/.npm/_logs/2023-02-13T00_02_48_304Z-debug-0.log
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.