typeorm-typedi-extensions
typeorm-typedi-extensions copied to clipboard
fix: Using Typeorm DataSource and Typegraphql: Cannot get Connection with name \"default\" from the ConnectionManager.
Description
Using Typeorm's new way of connecting to a data source with new Typeorm.DataSource({...})
, we cannot access the global typeorm connection through the typedi container. I'm using Typegraphql and when I run a query I get the response error:
Cannot get Connection with name \"default\" from the ConnectionManager. Make sure you have created the connection and called \"useContainer(Container)\" in your application before establishing a connection and importing any entity into TypeORM.
It only works if we create the connection using the now deprecated Typeorm.createConnection
.
As a side note, Typeorm has deprecated all container-related features in 0.3.0. How will this affect the future of this package and Typedi as a whole?
Minimal code-snippet showcasing the problem
import * as TypeGraphQL from 'type-graphql';
import { Container } from 'typeorm-typedi-extensions';
TypeORM.useContainer(Container);
export const AppDataSource = new DataSource(typeormOptions);
await AppDataSource.initialize(); // this will establish the connection, but Typegraphql can't find the connection
// await TypeORM.createConnection(typeormOptions); // this still works however
const schema = await TypeGraphQL.buildSchema({
...
container: Container,
});
Expected behavior
I expected to my query to be able to find the injected Repository and Connection and run the query.
Actual behavior
Typegraphql sends back the response:
Cannot get Connection with name \"default\" from the ConnectionManager. Make sure you have created the connection and called \"useContainer(Container)\" in your application before establishing a connection and importing any entity into TypeORM.
@nelsonfleig I'm just going through the process of updating (or at least considering updating) typeorm
to the newest version with all of the depreciations you're talking about.
Have you had any luck working around (possibly with a fork, etc) the issues you mentioned?
I hate breaking changes 😭
Hey someone fix that shit ?
This is so problematic. I'm stuck with updating to new Version which has deprecated containers
Hey, anyone has fixed this issue? I'm also stuck on this. Please help.
Same here 👎🏻