12
12
schema = graphene .Schema (name = 'Starwars Relay Schema' )
13
13
14
14
15
+ class Connection (relay .Connection ):
16
+ total_count = graphene .IntField ()
17
+
18
+ def resolve_total_count (self , args , info ):
19
+ return len (self .get_connection_data ())
20
+
21
+
15
22
class Person (DjangoNode ):
16
23
'''An individual person or character within the Star Wars universe.'''
17
24
class Meta :
18
25
model = models .People
19
26
exclude_fields = ('created' , 'edited' )
20
27
28
+ connection_type = Connection
29
+
21
30
22
31
class Planet (DjangoNode ):
23
32
'''A large mass, planet or planetoid in the Star Wars Universe,
24
33
at the time of 0 ABY.'''
25
34
climates = graphene .ListField (graphene .StringField ())
26
35
terrains = graphene .ListField (graphene .StringField ())
27
36
37
+ connection_type = Connection
38
+
28
39
@resolve_only_args
29
40
def resolve_climates (self ):
30
41
return [c .strip () for c in self .instance .climate .split (',' )]
@@ -41,6 +52,8 @@ class Meta:
41
52
class Film (DjangoNode ):
42
53
producers = graphene .ListField (graphene .StringField ())
43
54
55
+ connection_type = Connection
56
+
44
57
@resolve_only_args
45
58
def resolve_producers (self ):
46
59
return [c .strip () for c in self .instance .producer .split (',' )]
@@ -57,6 +70,8 @@ class Specie(DjangoNode):
57
70
hair_colors = graphene .ListField (graphene .StringField ())
58
71
skin_colors = graphene .ListField (graphene .StringField ())
59
72
73
+ connection_type = Connection
74
+
60
75
@resolve_only_args
61
76
def resolve_eye_colors (self ):
62
77
return [c .strip () for c in self .instance .eye_colors .split (',' )]
@@ -79,6 +94,8 @@ class Vehicle(DjangoNode):
79
94
'''A single transport craft that does not have hyperdrive capability'''
80
95
manufacturers = graphene .ListField (graphene .StringField ())
81
96
97
+ connection_type = Connection
98
+
82
99
@resolve_only_args
83
100
def resolve_manufacturers (self ):
84
101
return [c .strip () for c in self .instance .manufacturer .split (',' )]
@@ -92,6 +109,8 @@ class Starship(DjangoNode):
92
109
'''A single transport craft that has hyperdrive capability.'''
93
110
manufacturers = graphene .ListField (graphene .StringField ())
94
111
112
+ connection_type = Connection
113
+
95
114
@resolve_only_args
96
115
def resolve_manufacturers (self ):
97
116
return [c .strip () for c in self .instance .manufacturer .split (',' )]
0 commit comments