question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Connection "default" not found

See original GitHub issue

Issue type:

[x] question [ ] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [x] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[ ] latest [ ] @next [x] 0.2.14

I’ve tried the other issues related to this but none worked unfortunately.

I’m using Typeorm in combination with Express and Apollo Server

The createConnection step goes well, but when I’m calling a specific resolver (the Register one, a Graphql mutation resolver to sign up to my app), I’m getting Uncaught (in promise) Error: GraphQL error: Connection "default" was not found. in my browser console

How I create my connection :

await createConnection(connectionOptions);

the value of connectionOptions is what I have in my ormconfig.js :

module.exports = {
  name: "production",
  type: "postgres",
  host: "db", // db is the name of my Docker service running the database
  port: 5432,
  username: process.env.ORM_USER,
  password: process.env.ORM_PASSWORD,
  database: process.env.ORM_DB,
  synchronize: true,
  logging: false,
  entities: [process.env.ORM_ENTITIES],
  migrations: [process.env.ORM_MIGRATIONS],
  subscribers: [process.env.ORM_SUBSCRIBERS],
  cli: {
    entitiesDir: process.env.ORM_ENTITIES_DIR,
    migrationsDir: process.env.ORM_MIGRATIONS_DIR,
    subscribersDir: process.env.ORM_SUBSCRIBERS_DIR
  }
};

my env variables seem correct (ORM_ENTITIES = “dist/entity/**/*.js”, which is the correct path)

my User entity :

...
@Entity()
export class User extends BaseEntity {
  @PrimaryGeneratedColumn("uuid")
  id: string;

  @Column("text")
  email: string;

  @Column("text", { nullable: true })
  username: string | null;

  @Column("text")
  password: string;
...

The problem doesn’t seem to be in my resolver, because the console.logs I put in it are not reached

This issue occurs in production, I don’t have it in local development

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
drewjbartlettcommented, Apr 10, 2020

If this is still an issue for anyone, I’ve solved it by making a factory function:

import { getRepository } from 'typeorm/browser';
import { UserEntity, UserModel } from './schema';

export function getUserRepository() {
  return getRepository<UserModel>(UserEntity);
}

And then I import the function to use:

import { getUserRepository } from '...';

getUserRepository().findOne(1);
4reactions
wijourdilcommented, Oct 4, 2019

I got the same issue and solved it by using

getRepository(Entity).find()...

instead of

Entity.find()...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Connection "default" was not found with TypeORM
Solution is to make sure that you have exactly the same version installed in each package. To be on the safe side, delete...
Read more >
0.3.0: Connection "default" was not found for creating entities ...
Issue Description The datasource I'm using: export const dataSource = new DataSource({ type: "postgres", url: process.env.
Read more >
Connection "default" was not found with TypeORM-postgresql
I use TypeORM with NestJS and I am not able to save properly an entity. The connection creation works, postgres is running on...
Read more >
typeorm/typeorm - Gitter
I'm finding the official documentation incredibly confusing to piece together ... Looks like this entity is not registered in current "default" connection?
Read more >
Working with Connection | TypeORM Docs
Different connections must have different names. By default, if connection name is not specified it's equal to default . Usually, you use multiple...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found