5
5
import graphene
6
6
from graphene import resolve_only_args , relay
7
7
from graphene .contrib .django import DjangoNode , DjangoConnection
8
+ from graphene .contrib .django .filter import DjangoFilterConnectionField
9
+ from graphene .contrib .django .debug import DjangoDebugPlugin
8
10
9
11
import models
10
12
11
13
12
- schema = graphene .Schema (name = 'Starwars Relay Schema' )
14
+ schema = graphene .Schema (name = 'Starwars Relay Schema' , plugins = [ DjangoDebugPlugin ()] )
13
15
14
16
15
17
class Connection (DjangoConnection ):
@@ -24,6 +26,7 @@ class Person(DjangoNode):
24
26
class Meta :
25
27
model = models .People
26
28
exclude_fields = ('created' , 'edited' )
29
+ filter_fields = ('name' , )
27
30
28
31
connection_type = Connection
29
32
@@ -47,8 +50,10 @@ def resolve_terrains(self):
47
50
class Meta :
48
51
model = models .Planet
49
52
exclude_fields = ('created' , 'edited' , 'climate' , 'terrain' )
53
+ filter_fields = ('name' , )
50
54
51
55
56
+ @schema .register
52
57
class Film (DjangoNode ):
53
58
producers = graphene .String ().List
54
59
@@ -62,6 +67,7 @@ def resolve_producers(self):
62
67
class Meta :
63
68
model = models .Film
64
69
exclude_fields = ('created' , 'edited' , 'producer' )
70
+ filter_fields = {'episode_id' : ('gt' , )}
65
71
66
72
67
73
class Specie (DjangoNode ):
@@ -127,12 +133,12 @@ class Meta:
127
133
128
134
129
135
class Query (graphene .ObjectType ):
130
- all_films = relay . ConnectionField (Film )
131
- all_species = relay . ConnectionField (Specie )
132
- all_characters = relay . ConnectionField (Person )
133
- all_vehicles = relay . ConnectionField (Vehicle )
134
- all_planets = relay . ConnectionField (Planet )
135
- all_starships = relay . ConnectionField (Starship )
136
+ all_films = DjangoFilterConnectionField (Film )
137
+ all_species = DjangoFilterConnectionField (Specie )
138
+ all_characters = DjangoFilterConnectionField (Person )
139
+ all_vehicles = DjangoFilterConnectionField (Vehicle )
140
+ all_planets = DjangoFilterConnectionField (Planet )
141
+ all_starships = DjangoFilterConnectionField (Starship )
136
142
film = relay .NodeField (Film )
137
143
specie = relay .NodeField (Specie )
138
144
character = relay .NodeField (Person )
0 commit comments