You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to find the best way to be able to re-use a resolver for two sub-classes while also using dependency injection. I have the following superclass and sub-classes:
Instead of having all Queries/Mutations/Field Resolvers in the same file for both sub-classes I wanted to split them out and have a resolver for each sub-class. I've tried following along with the example of creating a base resolver here but I'm running into an issue where my call to my service just results in Can't call "viewPortfolio" of undefined error which leads me to believe that the service just isn't being injected properly. I attempted the following:
exportfunctioncreateBasePortfolioResolver<TextendsClassType>(suffix: string,ObjectTypeCls: T){
@injectable()// <--- tsyringe doesn't like this as the class is abstract.
@Resolver({isAbstract: true})abstractclassBasePortfolioResolver{constructor(@inject(PortfolioService)privateservice: PortfolioService){}
@Extensions({permissions: {operation: "view",resource: "portfolio"}})
@PermissionHandler(and(isAuthenticated,isOwnerOrAdmin("portfolio")))
@Query((returns)=>PortfolioUnionType)asyncviewPortfolio(@Arg("id")id: string): Promise<typeofPortfolioUnionType>{console.log("service ",this.service);returnawaitthis.service.viewPortfolio(id);}}returnBasePortfolioResolver;}// portfolioAResolver.tsconstPortfolioAResolver=createBasePortfolioResolver("portfolio",Portfolio);// portfolioBResolver.tsconstPortfolioBResolver=createBasePortfolioResolver("portfolio",Portfolio);
Is there a way I could possibly make this work? Any help would be greatly appreciated.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there,
I'm trying to find the best way to be able to re-use a resolver for two sub-classes while also using dependency injection. I have the following superclass and sub-classes:
I'm using tsyringe for DI and normally I'd create the Resolver to be something like:
Instead of having all Queries/Mutations/Field Resolvers in the same file for both sub-classes I wanted to split them out and have a resolver for each sub-class. I've tried following along with the example of creating a base resolver here but I'm running into an issue where my call to my service just results in Can't call "viewPortfolio" of undefined error which leads me to believe that the service just isn't being injected properly. I attempted the following:
Is there a way I could possibly make this work? Any help would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions