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

Typeorm breaking changes in 0.3.0+ affecting TypeGraphql examples #1252

Open
nelsonfleig opened this issue Mar 28, 2022 · 5 comments
Open

Typeorm breaking changes in 0.3.0+ affecting TypeGraphql examples #1252

nelsonfleig opened this issue Mar 28, 2022 · 5 comments
Labels
Community 👨‍👧 Something initiated by a community Documentation 📖 Issues about docs

Comments

@nelsonfleig
Copy link

nelsonfleig commented Mar 28, 2022

Describe the issue
Typeorm 0.3.0+ has released with many breaking changes for the Typegraphql examples. Notably, all container-related features in Typeorm have been depecreated affecting how TypeDI is used. Also the way to establish a typeorm connection to a DB with Typeorm.createConnection() has been depecrated in favour of Typeorm.DataSource.

At a first glance, the following examples have been affected:

typeorm-basic-usage
typeorm-lazy-relations

Are you able to make a PR that fix this?
Not currently

@MichalLytek MichalLytek added Community 👨‍👧 Something initiated by a community Documentation 📖 Issues about docs labels Mar 28, 2022
@laukaichung
Copy link

Has anyone managed to upgrade Typeorm to 0.3.0 with TypeGraphql?

@Cry0nicS
Copy link

Cry0nicS commented Jul 15, 2022

Has anyone managed to upgrade Typeorm to 0.3.0 with TypeGraphql?

Yes, @laukaichung . I'm currently working on a small project and I'm using TypeORM 0.3.6 with TypeGraphQL 1.1.1
I'm using both TypeDi for injection, as I'm using the repository pattern, as well as multiple data-sources (as I have a DS for a DB I only use for tests).

Do you have a concrete issue? You can check my project out, if you'd like. All basic examples work. You can also look at specific commits, as I work incrementally. It's not much, but it's honest work 🙃

I have only tried MySQL DB, but should work just as well with PostgreSql. Haven't worked with NoSql DBs though, so cannot comment on that.

@laukaichung
Copy link

laukaichung commented Aug 18, 2022

Has anyone managed to upgrade Typeorm to 0.3.0 with TypeGraphql?

Yes, @laukaichung . I'm currently working on a small project and I'm using TypeORM 0.3.6 with TypeGraphQL 1.1.1 I'm using both TypeDi for injection, as I'm using the repository pattern, as well as multiple data-sources (as I have a DS for a DB I only use for tests).

Do you have a concrete issue? You can check my project out, if you'd like. All basic examples work. You can also look at specific commits, as I work incrementally. It's not much, but it's honest work upside_down_face

I have only tried MySQL DB, but should work just as well with PostgreSql. Haven't worked with NoSql DBs though, so cannot comment on that.

Thank you for the example. Working fine so far. I guess typeorm-typedi-extensions isn't compatible because the set isn't exposed so I can't do Container.set(DataSource, dataSource); after the data source initialization.

Also, all of my resolvers need to be decorated with Service().

My resolver looks like this:

import { Service } from "typedi";
import { AppDataSource } from "../config/data-source";
import {  Args, Mutation, Resolver} from "type-graphql";

@Service()
@Resolver(() => User)
class UserResolver {

  // Won't work anymore because typeorm-typedi-extensions is uninstalled.
  // constructor(
  //   @InjectRepository(User) private repository: Repository<User>,
  // ) {}

 private readonly repository = AppDataSource.getRepository(User);

 @Mutation((returnType) => User)
 public create(@Args() args){
   this.repository.save(...args)
 }
}

If you are using type-graphql-dataloader you need to change its config because the typeorm.getConnection() is depreciated:

import { ApolloServer } from "apollo-server-express"; // Must be v3+
import { AppDataSource } from "../config/data-source";
import { ApolloServerLoaderPlugin } from "type-graphql-dataloader";

async function startServer(){
  await AppDataSource.initialize()

  const apollo = new ApolloServer({
    schema,
    plugins: [
      ApolloServerLoaderPlugin({
        typeormGetConnection: ()=> AppDataSource
      }),
    ],
  });
}


startServer()

@Cry0nicS
Copy link

typeorm-typedi-extensions

Why do you need this? Last update was 2 years ago...
I've just used TypeDI. Should be enough.

Also, all of my resolvers need to be decorated with Service().

Yup

You can also use the @Inject decorator (see the docs). I just got used to do things the "old way"

@rafaell-lycan
Copy link

I guess the examples should be updates targeting mostly the latest version. This way it would avoid such errors related to previous/unmaintained dependency versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Documentation 📖 Issues about docs
Projects
None yet
Development

No branches or pull requests

5 participants