Skip to content

Commit 3c0a29f

Browse files
corrected the resolver
1 parent dbf903d commit 3c0a29f

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

backend/family_tree/student/schema.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,26 @@ class Meta:
88
model= Student
99
fields= ("id","name","branch","year","picture","homeTown","extraCurriculars","socialMedia", "linkedIn","email","parentId","roll_no")
1010
filter_fields=["id","name","branch","year","email","parentId","roll_no"]
11-
11+
def tree_for_batch(root,info,batch):
12+
tree_for_batch=[]
13+
for student in batch:
14+
roll= student.roll_no
15+
pathObjects=[]
16+
while(Student.objects.get(roll_no=roll).parentId!="root"):
17+
student=Student.objects.get(roll_no=roll)
18+
pathObjects.append(student)
19+
roll= student.parentId
20+
pathObjects.append(Student.objects.get(roll_no=roll))
21+
tree_for_batch.append(pathObjects)
22+
return tree_for_batch
1223

1324
class Query(graphene.ObjectType):
1425
students=graphene.List(StudentType)
1526
children=graphene.List(StudentType, parent_id=graphene.String())
1627
student_path= graphene.List(StudentType, roll=graphene.String())
1728
student_sibling= graphene.List(StudentType, roll=graphene.String())
1829
student_search= graphene.List(StudentType, search_query=graphene.String())
19-
student_batch= graphene.List(StudentType, roll=graphene.String())
30+
student_batch= graphene.List(graphene.List(StudentType), roll=graphene.String())
2031

2132
def resolve_students(root,info):
2233
return Student.objects.all()
@@ -30,7 +41,7 @@ def resolve_student_path(root, info, roll):
3041
student=Student.objects.get(roll_no=roll)
3142
pathObjects.append(student)
3243
roll= student.parentId
33-
pathObjects.append(Student.objects.get(roll_no=roll))
44+
pathObjects.append(Student.objects.get(roll_no=roll))
3445
return pathObjects
3546

3647
def resolve_student_sibling(root,info, roll):
@@ -42,10 +53,11 @@ def resolve_student_batch(root,info,roll):
4253
current_node= Student.objects.get(roll_no=roll)
4354
year_of_node= current_node.year
4455
current_batch= Student.objects.filter(year=year_of_node)
45-
tree_for_batch=[]
46-
for person in current_batch:
47-
tree_for_batch.append(Query.resolve_student_path(root,info,person.roll_no))
48-
return tree_for_batch
56+
# tree_for_batch=[]
57+
# for person in current_batch:
58+
# tree_for_batch.append(Query.resolve_student_path(root,info,person.roll_no))
59+
# return tree_for_batch
60+
return tree_for_batch(root,info,current_batch)
4961

5062

5163
def resolve_student_search(root,info, search_query):

0 commit comments

Comments
 (0)