如何为MongoDB的collection.find()函数中找到的MongoDB排序属性实现GraphQL标量?

我正在尝试使用CMake Error: install(EXPORT "MyLibTargets" ...) includes target "MyLib" which requires target "absl_base" that is not in the export set. CMake Error: install(EXPORT "MyLibTargets" ...) includes target "MyLib" which requires target "absl_strings" that is not in the export set. CMake Error: install(EXPORT "MyLibTargets" ...) includes target "MyLib" which requires target "absl_str_format" that is not in the export set. 创建参数类型以通过GraphQL查询接受参数。我在说的type-graphqlMongoDB's native NodeJS driver documentation上的选项的属性。

sort

如您所见,简单类型很好,但是当涉及到排序对象之类的东西时,我不确定如何进行操作。

nestJS implements a date scalar like so

@ArgsType()
export class FindAllArgs implements FindOneOptions {
    @Field(type => Int,{ defaultvalue: 0,description: 'Sets the limit of documents returned in the query.' })
    @Min(0)
    limit?: number;

    // This is where the custom sort would go about.
    @Field(type => SortScalar)
    sort?: sortScalar;

    @Field(type => Int,description: 'Set to skip N documents ahead in your query (useful for pagination).' })
    @Min(0)
    skip?: number;
}

即使在示例中,它也使用returnTypeFunction import { Scalar,CustomScalar } from '@nestjs/graphql'; import { Kind,ValueNode } from 'graphql'; @Scalar('Date',type => Date) export class DateScalar implements CustomScalar<number,Date> { description = 'Date custom scalar type'; parseValue(value: number): Date { return new Date(value); // value from the client } serialize(value: Date): number { return value.getTime(); // value sent to the client } parseLiteral(ast: ValueNode): Date { if (ast.kind === Kind.INT) { return new Date(ast.value); } return null; } } 。我应该将@Scalar('Date',type => Date)替换为什么?我要为DateparseValueserialize输入什么?

wohongming 回答:如何为MongoDB的collection.find()函数中找到的MongoDB排序属性实现GraphQL标量?

您可以仅使用@InputType将对象嵌套在args中-您不需要标量,它们仅用于可序列化的事物,例如时间戳->数字,mongo id-> ObjectId实例等。

本文链接:https://www.f2er.com/3057486.html

大家都在问