Code Monkey home page Code Monkey logo

trpc-nestjs-adapter's Introduction

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.

trpc-nestjs-adapter's People

Contributors

macstr1k3r avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.