Closed jaydev-jainam closed 1 year ago
@jaydev-jainam Hey, can you please describe the issue here with the steps of reproduction, examples, actual and expected results.
This is my resolver Field
@ResolveField('reference',() => [ReferenceUnion])
@GraphqlLoader({
polymorphic: {
id: 'referenceId',
descriminator : 'type'
}
})
async reference(@Loader() loader : PolymorphicLoaderData<[CourseObjectType | UserObjectType],string,TestimonialTypeEnum>,
@SelectedUnionTypes() types : SelectedUnionTypesResult) {
const result = await this.testimonialService.getBatchReference(loader,types);
console.log(loader.ids)
return loader.helpers.mapOneToManyPolymorphicRelation(result, loader.ids,'referenceId');
}
And This is my service function for resolver field
async getBatchReference(loader : PolymorphicLoaderData<[CourseObjectType | UserObjectType],string,TestimonialTypeEnum>,
types : SelectedUnionTypesResult) {
let results = [];
for( let item of loader.polimorphicTypes){
switch(item.descriminator){
case TestimonialTypeEnum.INSTRUCTOR :
const instructors = await this.userRepository.createQueryBuilder("user")
.where({
id: In(item.ids)
})
.getMany()
console.log(instructors)
const instructorMap = this.mapper.mapArray(instructors,User,UserObjectType)
results.push({ descriminator: TestimonialTypeEnum.INSTRUCTOR, entities: instructorMap})
break ;
case TestimonialTypeEnum.COURSE :
const courses = await this.courseRepository.createQueryBuilder("course")
.setFindOptions({ relations: ["courseMentors","courseLanguages"] })
.where({
id: In(item.ids)
})
.getMany()
const courseMap = this.mapper.mapArray(courses,Course,CourseObjectType)
results.push({ descriminator: TestimonialTypeEnum.COURSE, entities: courseMap})
break ;
}
}
console.log(results)
return results;
}
The problem arises when attempting to map Course and Instructor entities to the Testimonial entity, which have a polymorphic relationship. The provided code snippets appear to be correctly structured, but there may be a discrepancy in the configuration or implementation that prevents successful mapping. Further examination is needed to pinpoint the exact source of the problem. We have many to One relation of testimonial and course to instructor.In resolver field its return null even I have reference id in entity.
@Adrinalin4ik Can you help me
What does this.mapper.mapArray do?
This will mapped entity into dto type
@Adrinalin4ik
Can you show me what the output of your mapper
Another question, what is your timezone and available time? Maybe we can sync with you and you'll show me.
The Timezone is IST in India, and I will be available from 10 am to 5 pm according to the India timezone, We can do a google meet or zoom call?
Can you leave your email, I'll arrange some time
jaydev.jadav@jainam.biz
@jaydev-jainam you wasn't attended to call. You didn't explain your problem properly so I can't help you.
@jaydev-jainam I guess the problem here with your this.mapper.mapArray. Could you provide me info about it?
Closed due to inactivity
https://github.com/Adrinalin4ik/Nestjs-Graphql-Tools/discussions/28#discussion-5619026
@Adrinalin4ik Can you please resolve this issue