[英]NestJs - Graphql Error Cannot determine a GraphQL input type for the <Field>. Make sure your class is decorated with an appropriate decorator
[英]Graphql Nestjs add arguments to type field
你好,你好嗎,過去一周我一直在學習 Nestjs,並且非常喜歡它。 我目前正在將它與 Prisma 2 一起使用來構建 graphql 服務器。 我想在 graphql 類型字段中添加 arguments 以便能夠使用棱鏡過濾或排序結果。 明確地說,我希望能夠執行以下架構
query {
findUniqueUser(where: { id: 1 }) {
id
email
name
posts(where: { title: { contains: "a" } }, orderBy: { createdAt: asc }, first: 10, skip: 5) {
id
title
comments(where: { contain: { contains: "a" } }) {
id
contain
}
}
}
}
我正在使用庫@paljs/plugins從 GraphQLResolveInfo 中提取信息並對 prisma 進行查詢。 我還使用庫prisma-nestjs-graphql自動生成所有 graphql 類型定義。 有沒有人嘗試過使用nestjs? 謝謝你,祝你有美好的一天
編輯:我使用代碼優先 graphql
編輯 2:四處挖掘后,我找到了一種使用@ResolveField
的方法。
@Query((returns) => Patient, { nullable: true, name: "patient" })
async getPatient(@Args() params: FindUniquePatientArgs, @Info() info: GraphQLResolveInfo) {
const select = new PrismaSelect(info).value;
params = { ...params, ...select };
return this.prismaService.patient.findUnique(params);
}
@ResolveField(() => File)
async files(@Parent() patient: Patient, @Args() params: FindManyFileArgs) {
return patient.files;
}
我不知道這是否是最好的方法,所以我暫時不回答這個問題。
我將把它留在這里作為答案
@Query((returns) => Patient, { nullable: true, name: "patient" })
async getPatient(@Args() params: FindUniquePatientArgs, @Info() info: GraphQLResolveInfo) {
const select = new PrismaSelect(info).value;
params = { ...params, ...select };
return this.prismaService.patient.findUnique(params);
}
@ResolveField(() => File)
async files(@Parent() patient: Patient, @Args() params: FindManyFileArgs) {
return patient.files;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.