vesper icon indicating copy to clipboard operation
vesper copied to clipboard

EntityManager doesn't work with existing TypeORM project

Open claytoncasey01 opened this issue 7 years ago • 2 comments

We are working with an existing TypeORM project and have been working on getting things moved over to Vesper recently. The samples work just fine but when we use our existing Database and TypeORM models the injected EntityManger in Controllers does not contain the needed connection data.

It does connect properly to the database, if we change the password it fails to start due to MySQL issues.

Here is a screenshot inside the startup of Vesper where the connection looks fine: screen shot 2018-11-02 at 1 36 08 pm

After startup in the controller: screen shot 2018-11-02 at 12 38 49 pm

Error in playground: screen shot 2018-11-02 at 1 43 47 pm

claytoncasey01 avatar Nov 02 '18 18:11 claytoncasey01

This seems to be caused by the controller referencing a different instance of TypeORM to Vesper.

Changing the import line to this solved the issue for me: import { EntityManager } from 'vesper/node_modules/typeorm';

solarflare045 avatar Nov 16 '18 00:11 solarflare045

I ~solved~ tried solving registering the EntityManager:

import { bootstrap } from "vesper";
import { ManufacturerController } from "presentation/web/controllers/manufacturer-controller";
import { Manufacturer } from "entities/manufacturer";
import { Connection, EntityManager, getManager } from "typeorm";

export const init = (connection: Connection) => new Promise(resolve => {
	bootstrap({
		port: 3001,
		controllers: [
			ManufacturerController
		],
		entities: [
			Manufacturer
		],
		schemas: [
			`${__dirname}/../infrastructure/schema/**/*.graphql`
		],
		graphIQLRoute: '/graphiql',
		setupContainer: async (container, action) => {
			container.set(EntityManager, getManager())
		}
	}).then(resolve)
});

UPDATE: Relations do not work registering the EntityManager

wufe avatar May 21 '19 18:05 wufe