question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Idiomatic schematics for NestJS

See original GitHub issue

Expected Behavior

It would be awesome if we could enhance the @nrwl/nest schematics to be more idiomatic to an Nx workspace, and support this syntax:

nx generate @nrwl/nest:<schematic> --project <project>.

Current Behavior

Currently we add @nestjs/schematics as a peer dependency and while that allows you to generate NestJS code, there are a few things with it.

Firstly, it doesn’t have the notion of projects, so in order to generate code in one of our libraries we need to pass in the full path, like so:

$ nx g @nestjs/schematics:service todo --sourceRoot libs/todo/src/lib 
CREATE libs/todo/src/lib/todo/todo.service.spec.ts (446 bytes)
CREATE libs/todo/src/lib/todo/todo.service.ts (88 bytes)
UPDATE libs/todo/src/lib/todo.module.ts (194 bytes)

I would love to be able to just to nx g @nrwl/nest:service --project todo - similar to for instance @nrwl/angular or @nrwl/react.

Additionally, @nestjs/schematics has a couple of schematics that don’t really make sense in the context of a Nx Workspace:

  • angular-app
  • application
  • configuration
  • library
  • sub-app

Context

To start, I think it makes sense to port over some of the schematics that are most frequently used (at least by me that is, your milage may vary).

  • controller
  • module
  • resolver
  • service

These are some other schematics from @nestjs/schematics that might be good to port at some point:

  • class
  • decorator
  • filter
  • gateway
  • guard
  • interceptor
  • interface
  • middleware
  • pipe
  • provider

Lastly, I’d love to add a schematic that allows configuring GraphQL in a nest module. So nx g @nrwl/nest:graphql --project api would install and configure @nestjs/graphql in the api project.

Other

I’m opening this issue to see if it makes sense to add this. If so, I’d be happy to create a PR that adds the first 4 schematics I listed above, and later optionally ad some more.

Also, as I see myself using these schematics quite a bit in the future, I’m happy to take on maintaining these schematics inside nrwl/nx for the foreseeable future.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
yharaskrikcommented, Jul 10, 2020

@beeman sounds great. Send me a message in the slack channel?

1reaction
Cammisulicommented, May 6, 2020

Hi @beeman, we need to think of a way to dynamically map all the nest schematics to support the --project flag. Currently we would have to do what you suggested and have a one to one mapping between nest and nrwl. And there’s a lot. It’ll be a big maintenance burden ☹️

This is something that we need to talk about more for sure.

In the meantime, you can create workspace schematics that map the ones you need for your repo.

As for the graphql one, you’re more than welcomed to add support for that 😄 . If you need help with it, you can reach out and I’ll be more than happy to help you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@nestjs/schematics - npm
Nest - modern, fast, powerful node.js web framework (@schematics). Latest version: 9.0.3, last published: 4 months ago.
Read more >
Build Fullstack Apps with NestJS, Hasura, and GraphQL APIs
In this post, we'll give a general overview to NestJS, how it works in the context of Hasura and how GraphQL APIs can...
Read more >
Angular Schematics for custom components in project repo : r/angular
Hi everyone, I'm pretty new when it comes to Angular Schematics but I am ... Is there an idiomatic way to handle render/fetch...
Read more >
A REST SDK Generator for NestJS
Full support for idiomatic NestJS modules and controllers ... nest-sdk-generator analyzes your NestJS API using a provided configuration file, and produces ...
Read more >
Building gRPC Service Server Note CRUD API with node.js
gRPC Client and Server Diagram ... It then lets you generate idiomatic client and server stubs from your service definition in a variety...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found