Description
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.