Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Using Typeorm DataSource and Typegraphql: Cannot get Connection with name \"default\" from the ConnectionManager. #60

Open
nelsonfleig opened this issue Mar 27, 2022 · 6 comments
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@nelsonfleig
Copy link

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 nelsonfleig added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Mar 27, 2022
@kevin-mitchell
Copy link

@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?

@JefferyHus
Copy link

I hate breaking changes 😭

@alexisvisco
Copy link

Hey someone fix that shit ?

@paramsinghvc
Copy link

This is so problematic. I'm stuck with updating to new Version which has deprecated containers

@yugank-zangula
Copy link

Hey, anyone has fixed this issue? I'm also stuck on this. Please help.

@sciotta
Copy link

sciotta commented Dec 20, 2022

Same here 👎🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.
Development

No branches or pull requests

7 participants