type-graphql
type-graphql copied to clipboard
Typeorm breaking changes in 0.3.0+ affecting TypeGraphql examples
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
Has anyone managed to upgrade Typeorm to 0.3.0 with TypeGraphql?
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.
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()
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"
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.