NestJS中多个graphql解析器实现的问题 [英] Problem with multiple graphql resolver implementations in nestjs

查看:269
本文介绍了NestJS中多个graphql解析器实现的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习NestJS和GraphQL.我从在UserModule中定义的单个解析器类UserResolver开始.此类提供了读取用户列表或特定用户列表的方法.方法用@Query()装饰,提供了user.graphql文件,在AppModule中初始化了GraphQL,所有操作均在文档中进行了描述.一切正常,我可以通过Insomnia Tool或Playground获取用户列表或特定用户.我很开心!

I just started learning NestJS and GraphQL. I started with a single resolver class UserResolver defined in UserModule. This class provides methods to read a list of users or a specific user. Methods are decorated with @Query(), a user.graphqlfile is provided, GraphQL is initialized in AppModule, all as described in the docs. All works well, I can get a list of users or specific user through Insomnia Tool or through Playground. I am happy!

现在,我创建了第二个模块RoleModule.我创建了一个role.graphql文件和一个RoleResolver类,基本上我复制了User的所有工作,但是这次是Role的.可以识别类型Role的GraphQL类型定义以及role.graphql文件中的查询定义.不能识别的是我在RoleResolver类中的Query()实现,它们没有被调用.

Now I have created a second module, RoleModule. I created a role.graphql file and a RoleResolver class, I basically replicated all the work done for User but this time for Role. The GraphQL type definition for type Role as well as the Query definitions in the role.graphql file are recognized. What is not recognized are my Query() implementations in the RoleResolver class, they are not getting invoked.

如果我将所有与这些Role相关的@Query()定义放入UserResolver类中,则这些与Role相关的查询现在将被调用.

If I put all these Role related @Query() definitions into the UserResolver class, these Role related queries are now getting invoked.

这是预期的行为吗?我是否需要将所有GraphQL查询定义放入一个类中?是否可以将NestJS-GraphQL解析器实现分布在多个模块上?难道我做错了什么?请帮忙.

Is that expected behavior? Do I need to put all my GraphQL query definitions into a single class? Is it possible to spread NestJS-GraphQL resolver implementations over several modules? Am I doing something wrong? Please help.

推荐答案

确保从@nestjs/graphql导入Query,而从@nestjs/common导入不是.

Make sure that you import Query from @nestjs/graphql and not from @nestjs/common.

这篇关于NestJS中多个graphql解析器实现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆