Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/macstr1k3r/trpc-nestjs-adapter
An adapter, allowing you to use TRPC inside of Nest.JS
https://github.com/macstr1k3r/trpc-nestjs-adapter
Last synced: 2 months ago
JSON representation
An adapter, allowing you to use TRPC inside of Nest.JS
- Host: GitHub
- URL: https://github.com/macstr1k3r/trpc-nestjs-adapter
- Owner: macstr1k3r
- Created: 2023-01-24T07:40:59.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-09-29T11:39:48.000Z (over 1 year ago)
- Last Synced: 2023-09-29T15:04:52.511Z (over 1 year ago)
- Language: TypeScript
- Size: 158 KB
- Stars: 99
- Watchers: 4
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
- awesome-javascript - trpc-nestjs-adapter
- awesome-javascript - trpc-nestjs-adapter
README
# tRPC - Nest.JS Adapter
- Allows you to use Trpc with Nest.JS.
- Allows you to use request scoped Nest.JS providers
- Allows you to use Nest.JS's great module system## Feature support
I don't use all of the features tRPC has :/Both __queries__ and __mutations__ work.
I __haven't__ tested subscriptions yet.
Batching __doesn't__ work. Currently it't not possible to create multiple requests from 1 single HTTP request in Nest.JS (or it's a skill issue :) )
## How
See the `example` folder in this repo, but briefly
```bash
yarn add trpc-nestjs-adapter
````main.ts`
``` ts
// Standard nest.js main.ts
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app.module';async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}bootstrap();
````app.module.ts`
```ts
import { Module } from '@nestjs/common';
import { TrpcModule } from 'trpc-nestjs-adapter';
import { rootRouter } from './trpc/root-trpc.router.ts';
import { createContext } from './trpc/create-context.ts';@Module({
imports: [
AModule,
TrpcModule.forRoot({
path: '/trpc',
router: rootRouter,
createContext,
}),
],
})
export class AppModule { }```
### Inside of your procedures
```ts
export const exampleMutation = trpc.procedure
.input()
.mutation(async ({ ctx })=>{
const nestService = await ctx.resolveNestDependency(SomeNestService);await nestService.someServiceMethod()
})
```#### Note
The package is marked `alpha` for a reason, but mostly It's not documented very well.If/When/As the package gains traction I'll improve the example & related docs.