1
1
import graphene
2
2
from graphene_django import DjangoObjectType
3
3
from student .models import Student
4
+ from django .db .models import Q
4
5
5
6
class StudentType (DjangoObjectType ):
6
7
class Meta :
@@ -13,6 +14,8 @@ class Query(graphene.ObjectType):
13
14
students = graphene .List (StudentType )
14
15
children = graphene .List (StudentType , parentId = graphene .String ())
15
16
student_path = graphene .List (StudentType , roll = graphene .String ())
17
+ student_sibling = graphene .List (StudentType , roll = graphene .String ())
18
+ student_search = graphene .List (StudentType , search_query = graphene .String ())
16
19
17
20
def resolve_students (root ,info ):
18
21
return Student .objects .all ()
@@ -28,5 +31,14 @@ def resolve_student_path(root, info, roll):
28
31
roll = student .parentId
29
32
pathObjects .append (Student .objects .get (roll_no = roll ))
30
33
return pathObjects
34
+
35
+ def resolve_student_sibling (root ,info , roll ):
36
+ student = Student .objects .get (roll_no = roll )
37
+ return Student .objects .filter (parentId = student .parentId ).exclude (roll_no = roll )
38
+
39
+
40
+ def resolve_student_search (root ,info , search_query ):
41
+ return Student .objects .filter (Q (name__icontains = search_query ) | Q (roll_no__icontains = search_query ))[0 :8 ]
42
+
31
43
32
44
schema = graphene .Schema (query = Query )
0 commit comments