【发布时间】:2021-09-21 10:14:37
【问题描述】:
大家好,我在我的 nestJS 应用程序中遇到了冲突/覆盖问题。
那么问题是什么:
我有解析器 A
@Resolver('ResolverA')
export class SomePageResolver {
constructor(private readonly someService: someService) {
}
@Query(() => someType)
theThingThatMessesUpStuff(
@Args('params') params: HttpParamsInput,
@Context(TokenPipe) authorization: string,
): Observable<ActionSetsPageType> {
return this.someService.doSomething(params, authorization)
}
}
还有一个解析器 B
@Resolver('ResolverB')
export class SomePageResolver{
constructor(private readonly someService: someService) {
}
@Query(() => someOtherType)
theThingThatMessesUpStuff(
@Args('params') params: HttpParamsInput,
@Context(TokenPipe) authorization: string,
): Observable<ActionSetsPageType> {
return this.someService.doSomethingElse(params, authorization)
}
}
Resolver A 分别是 Module A 的一部分,Resolver B 是 Module B 的一部分。
根据我的构建,Module A 和 Module B 有可能被导入到单个模块(单个父模块)中,这会导致覆盖问题。
问题的本质是,当两个模块都是构建的一部分时,如果客户端查询theThingThatMessesUpStuff,它将使用最后导入的模块进行查询
// some code
@Module({
imports: [
// some imports
ModuleB,
ModuleA
]
})
// some more code
如果使用上面的示例配置,每当客户端尝试查询 theThingThatMessesUpStuff 字段时,查询将由 ModuleA 内部的实现解决,其中一些功能(在与此相关的前端内部构建)客户端将期望在ModuleB中实现
现在回到主要问题,有没有一种方法可以在不涉及太多人的情况下创建一个验证,以保证在 nestJS 应用程序范围内只存在唯一的 GQL 查询。
【问题讨论】:
标签: javascript typescript nestjs gql