Closed herbertpimentel closed 3 years ago
The container instance is always injected as the last extra parameter to allow the lib to work with JS where there are no decorators.
I see two possible reasons:
reflect-metadata
in the very first line of your code that can cause problemsContainer.get
call, you need to request the service from the container to auto-inject the dependenciesttps://github.com/typestack/typedi#basic-usage)Both of these concepts have examples in the project readme: https://github.com/typestack/typedi
@NoNameProvided Thanks for the quick reply,
reflect-metadata
is being called on the /page/api/graphql.ts this will be the very first file to be loaded on this api.
and the call for Container.get
should be made by the typegraphql as specified in here https://typegraphql.com/docs/dependency-injection.html
The main difference I see from my code apollo-server-micro
to the example apollo-server
its uses a differente package for the server
This is an issue with how your app is built. It seems the meta-information about the parameter types are stripped by next build
,
It should have meta data applied like this:
but your build version looks like this:
I cannot help with this sorry. You are probably best of asking this on the Next repo. Your question should be about how to config the build process to preserve the emitted type information by Typescript.
Now you that you told me that metadata has been stiped off by nextjs. I could fix that.
Next.js does not use TSC (the original TypeScript compiler) and instead relies on Babel's @babel/preset-typescript package. Because of that, those tsconfig.json tweaks (to keep metadata on objects) do not have any effect.
Instead, I added custom Babel configuration in my Next.js project and included the equivalent options for Babel
{
"presets": [
[
"next/babel",
{
"class-properties": {
"loose": true
}
}
]
],
"plugins": [
"babel-plugin-transform-typescript-metadata",
["@babel/plugin-proposal-decorators", { "legacy": true }]
]
}
For future reference https://dev.to/unframework/getting-typeorm-to-work-with-next-js-and-typescript-1len
Glad it worked out. I am adding the docs label as this can be useful for many.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I am trying following the simple typegraphql example, but using it as handle inside of nextjs app.
The problem: Everytime I am injecting the service it comes to me as "ContainerInstance" instead of the specific service
Here is a public repo to with this https://github.com/herbertpimentel/supersimples
So what I am possible doing wrong ?!