1.0.0-alpha.11 • Published 10 months ago

trpc-nestjs-adapter v1.0.0-alpha.11

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

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.

How

See the example folder in this repo, but briefly

yarn add trpc-nestjs-adapter

main.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<NestExpressApplication>(AppModule);
  await app.listen(3000);
}

bootstrap();

app.module.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

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.

10.0.0-alpha.11

10 months ago

1.0.0-alpha.11

10 months ago

1.0.0-alpha.10

1 year ago

1.0.0-alpha.9

1 year ago

1.0.0-alpha.8

1 year ago

1.0.0-alpha.7

1 year ago

1.0.0-alpha.6

1 year ago

1.0.0-alpha.5

1 year ago

1.0.0-alpha.4

1 year ago

1.0.0-alpha.3

1 year ago

1.0.0-alpha.2

1 year ago

1.0.0-alpha.1

1 year ago

0.0.1-alpha3

1 year ago

0.0.1-3

1 year ago

0.0.1-2

1 year ago

0.0.1-1

1 year ago

0.0.1

1 year ago