我需要从 prisma 类型中解析自定义解析器。但是在这种情况下我无法访问孩子,course
或者subjects
,我的person
类型只能解析一个级别的数据。
部门:
"nexus": "0.11.7",
"nexus-prisma": "0.3.7",
"prisma-client-lib": "1.30.0",
...
数据模型:
type Person {
id: ID! @unique
firstName: String!
secondName: String
firstSurname: String!
secondSurname: String
sex: SexTypes
address: String
commune: Commune
region: Region
course: Course
phone: String
state: StudentStateTypes @default(value: ACTIVE)
user: User! @relation(name: "UserPerson", onDelete: CASCADE)
birthday: DateTime
registrationNumber: String
listNumber: Int
previousSchool: OtherSchool
scholarship: Scholarship
createdAt: DateTime!
updatedAt: DateTime!
}
type Course {
id: ID! @unique
client: Client
name: String!
person: [Person!]!
teacher: User
subjects: [Subject!]!
evaluations: [Evaluation!]!
createdAt: DateTime!
updatedAt: DateTime!
}
type Subject {
id: ID! @unique
client: Client
name: String!
date: DateTime
isEvaluable: Boolean
order: Int
course: [Course!]!
evaluations: [Evaluation!]!
createdAt: DateTime!
updatedAt: DateTime!
}
type Evaluation {
id: ID! @unique
client: Client
name: String!
date: DateTime!
period: Int!
description: String
coefficientTwo: Boolean
course: Course!
subject: Subject
qualifications: [Qualification!]! @relation(name: "EvaluationQualification", onDelete: CASCADE)
createdAt: DateTime!
updatedAt: DateTime!
}
type Qualification {
id: ID! @unique
client: Client
value: Float!
evaluation: Evaluation! @relation(name: "EvaluationQualification", onDelete: SET_NULL)
person: Person
createdAt: DateTime!
updatedAt: DateTime!
}
我的解析器:
export const query = extendType({
type: 'Query',
definition (t: any) {
t.field('qualificationsCustom', {
type: 'Person',
args: {
id: idArg()
},
resolve: async (parent: any, args: any, ctx: any) => {
const person = await ctx.prisma.person({ id: args.id })
const qualifications = person && person.course.subjects.reduce((acc: any, subject: any) => {
acc.push({
subject: subject.name
})
return acc
})
console.log(qualifications)
}
})
}
})
person
变量只解决下一个:
{
birthday: '2008-10-27T00:00:00.000Z',
secondName: 'Gisel',
...
并且person.course
未定义:/
我做错了什么?