Type-graphql: Is there anyway to call a resolver from another resolver

Created on 8 Apr 2018  路  3Comments  路  Source: MichalLytek/type-graphql

Is there any way to fetch data from another resolver without using graphql?
For example:

````
@Resolver()
class ItemResolver{
item(@Args(){id}:SomeArgs){
return {someData:[]}
}
}

@Resolver()
class BrandResolver{
async brand(@Args(){brandId}:SomeArgs){
let data = await ItemResolver.item({5})
}
}
````

Question Solved

Most helpful comment

typedi is your friend.

All 3 comments

typedi is your friend.

https://19majkel94.github.io/type-graphql/docs/dependency-injection.html

@Service()
class ItemService {
  getItem(id: number) {
    return {someData:[]}
  }
}
@Resolver()
class ItemResolver{
    constructor(private itemService: ItemService) {}
    async item(@Args(){id}:SomeArgs){
          return await itemService.getItem(id);
     }
}
@Resolver()
class BrandResolver{
     constructor(private itemService: ItemService) {}
     async brand(@Args(){brandId}:SomeArgs){
            let data = await itemService.getItem(id);
     }
}

Thanks all.

Was this page helpful?
0 / 5 - 0 ratings