Closed gempain closed 4 years ago
To properly debug this, a minimum reproduction would be required. Are any of the services from MyService
marked as REQUEST
scoped? That's the only thing I could think of that could be causing an issue
Please provide a minimum reproduction repository.
@jmcdo29 @kamilmysliwiec trying
@jmcdo29 right on Sir ! Took me a while, but I crawled my service dependency graph and bumped on a request scoped service. I came here for this kind of hint, thanks a lot for pointing me in the right direction.
By the way, I tried compodoc to get a good picture of the dependency graph, but it's actually not that great. I think there is a place for a little utility tool to generate user friendly, navigable service dependency graphs in Nest. Just a thought :)
@gempain I had a feeling it was dealing with request scoped dependencies. Glad that helped.
As for the doc generator, I'm actually working on a tool for that called nestjs-spelunker. It's still in early development though, and needs a lot of work.
Interesting, I actually happened to find that page while searching for an alternative to compodoc. I looked at the example JSON. I think you've done most of the work, because now you just need to generate the graph. I really like the way that graphql-voyager works: you just plug in their express middleware and it gives you an amazing interactive graph you can navigate and manipulate. Seems like your API approaches that idea. So many services in a real world app that you get lost in the dependencies, and this would be great to find circular dependencies.
I plan on extending the JSON graph to an html template that is interactive so that it is easier to read through the dependency graph. Like I said, the project is still in early development, mainly I wanted a proof of concept before going further. I'll need to think about finding the scope of each dependency as well, thanks to this issue 😄. Find me on Discord if you want to discuss further
Bug Report
Current behavior
Take the following gateway:
If I uncomment
// private readonly myService: MyService,
, the constructor is never called, the server starts and works for controllers, resolvers and pretty much everything, but I getMyService
lies in another module that is imported in myNotificationsModule
and depends onEventService
. There are no circular dependencies. I have debugged the gateway whenMyService
is not commented out, and noticed that whenafterInit
is called,this.eventService
,this.myService
andthis.logger
are undefined, onlythis.server
is defined.Input Code
I could not reproduce with a minimal example, I would have to share too much prroprietary code. I could definitely share some code with you privately.
Expected behavior
I would expect the gateway to wait for all dependent services to be instantiated.
Environment
For Tooling issues:
v12.13.1
OSX 10.15.3