如何使用';图ql至mongodb';是否使用NestJS(类型为graphql)?

如何使用';图ql至mongodb';是否使用NestJS(类型为graphql)?,graphql,nestjs,graphql-js,typegraphql,Graphql,Nestjs,Graphql Js,Typegraphql,我有当前的解析器功能: /******************** *recipe.resolver.ts ********************/ 从'@nestjs/graphql'导入{Args,Info,Query,Resolver,}; 从“./Recipe.model”导入{Recipe}; 从“./recipe.service”导入{RecipeService}; 从“./entities/shared/dto/find all.args”导入{FindAllArgs}; @分解

我有当前的解析器功能:

/********************
*recipe.resolver.ts
********************/
从'@nestjs/graphql'导入{Args,Info,Query,Resolver,};
从“./Recipe.model”导入{Recipe};
从“./recipe.service”导入{RecipeService};
从“./entities/shared/dto/find all.args”导入{FindAllArgs};
@分解器(of=>Recipe)
导出类RecipeResolver{
构造函数(私有只读recipeService:recipeService){}
@查询(返回=>[Recipe])
异步配方(
@Args()findAllArgs:findAllArgs,
@Info()信息,
):承诺{
返回此.recipeService.findAll(信息,findAllArgs);
}
}
它利用当前的服务功能:

/********************
*配方服务
********************/
从“mongodb”导入*作为mongo;
从'@nestjs/common'导入{Injectable};
从“./Recipe.model”导入{Recipe};
从“nest mongodb”导入{InjectCollection};
从“./entities/shared/dto/find all.args”导入{FindAllArgs};
@可注射()
导出类服务{
构造函数(@InjectCollection('Recipe')私有只读recipeCollection:mongo.Collection){}
异步findAll(信息,findAllArgs:findAllArgs):承诺{
const queryAstFields=info.fieldNodes[0].selectionSet.selections;
让idAbsent=true;
const requestedFields=queryAstFields.reduce(
(obj,项目)=>{
const fieldName=item.name.value;
如果(字段名=='id'){
idAbsent=false;
}
返回Object.assign(obj,{[fieldName]:true})
}, {});
如果(idAbsent){
requestedFields.\u id=false;
}否则{
删除requestedFields.id;
}
返回这个.recipeCollection.find({},{projection:requestedFields,…FindArgs}).toArray();
}
}
}
我的args DTO如下所示:

/********************
*find-all.args.ts
********************/
从“类验证器”导入{Min};
从'type graphql'导入{ArgsType,Field,Int};
从“mongodb”导入{FindOneOptions};
@ArgsType()
导出类FindAllArgs实现FindOneOptions{
@字段(类型=>Int,{defaultValue:0})
@最小值(0)
跳过?:数字;
@字段(类型=>Int,{defaultValue:0})
@最小值(0)
限制?:数量;
}
如您所见,我已经在尝试利用MongoDB的
投影
限制
,以及
跳过
函数中的选项参数。然而,我最近了解到了mongodb的
graphql
。它似乎完全完成了我正在做的事情。我想用它;但是,我不确定如何将其融入NestJS围绕GraphQL的解析器和
键入GraphQL的
参数的方式中

我假设我必须在解析器中使用它,但是它有getMongoDbQueryResolver和getGraphQLQueryArgs,我不知道如何添加它们

存储库中有一个,但我不确定如何实现它

我想我会尝试手动重做
ArgsType
中的所有内容,但我遇到了为不是
数字
字符串
布尔值
的内容定义类型的问题;已经有标量类型的

/********************
*find-all.args.ts
********************/
从“类验证器”导入{Min};
从'type graphql'导入{ArgsType,Field,Int};
从“mongodb”导入{FindOneOptions};
@ArgsType()
导出类FindAllArgs实现FindOneOptions{
@字段(type=>Int,{defaultValue:0,description:'设置查询中返回的文档的限制。'})
@最小值(0)
限制?:数量;
//排序?:任何[]对象;