我正在使用 Mikro-ORM 和 type-graphql 创建一个 GraphQL 服务器,对于某些 GraphQL 查询,我需要根据查询参数的无效性为查找操作动态创建“where”参数。我的问题是关于“where”参数的输入。
@Query(() => [Topic])
topics(
@Ctx() { em }: Context,
@Arg("filter") { subject_id, approved }: TopicArgs
): Promise<Topic[]> {
const where: any = {};
if (approved) where.approved = approved;
return em.find(Topic, filter);
}
我尝试FilterQuery<Topic>
基于调用签名使用,find
但这会在赋值行引发“类型上不存在属性”错误,并在调用find
函数行引发“类型不兼容”错误。any
除了在代码片段中使用 like 之外,还有其他解决方案吗?