Closed leandroluk closed 1 year ago
Tsyringe works well for TypeGraphQL projects. What have you tried and what was not working for you?
Yes, it's possible! \
Most IOC containers have the get
function to retrieve an instance of the given class type. tsyringe
instead have the resolve
function. \
Therefore, you have to change the container
option when building the schema to instruct type-graphql
how to retrieve (get) a class instance from a class type:
import { container } from 'tsyringe';
const schema = await buildSchema({
// ...
container: { get: (cls) => container.resolve(cls) }
});
@leandroluk Can we close this?
Yes, it's possible! Most IOC containers have the
get
function to retrieve an instance of the given class type.tsyringe
instead have theresolve
function. Therefore, you have to change thecontainer
option when building the schema to instructtype-graphql
how to retrieve (get) a class instance from a class type:import { container } from 'tsyringe'; const schema = await buildSchema({ // ... container: { get: (cls) => container.resolve(cls) } });
I can confirm this works, using tsyringe and typegraphql in a large production project :)
How to register the resolvers with tsringe? I get the following error.
TypeInfo not known for "AuthResolver"
@clayrisser See tsyringe example
Describe the issue I have a project using DI with tsyringe and i should to add graphql using type-graphql, but in documentation is only listed the TypeDI as a dependency injection lib
Are you able to make a PR that fix this? If is possible to use Tsyringe, plesse add some example in doc's
Additional context N/A