Мне нужно разрешить пользовательский распознаватель из типа призмы. Но я не могу получить доступ к детям в этом случае 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
не определено: /
Что я делаю не так?