8000 Improved grapheme version and use custom Connection for Nodes · graphql-python/swapi-graphene@3baa609 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 3baa609

Browse files
committed
Improved grapheme version and use custom Connection for Nodes
1 parent 7af9399 commit 3baa609

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

requirements_base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Django==1.8.5
2-
graphene[django]==0.1.5
2+
graphene[django]==0.1.6.0
33
django-graphiql==0.3.1.7

starwars/schema.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,30 @@
1212
schema = graphene.Schema(name='Starwars Relay Schema')
1313

1414

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+
1522
class Person(DjangoNode):
1623
'''An individual person or character within the Star Wars universe.'''
1724
class Meta:
1825
model = models.People
1926
exclude_fields = ('created', 'edited')
2027

28+
connection_type = Connection
29+
2130

2231
class Planet(DjangoNode):
2332
'''A large mass, planet or planetoid in the Star Wars Universe,
2433
at the time of 0 ABY.'''
2534
climates = graphene.ListField(graphene.StringField())
2635
terrains = graphene.ListField(graphene.StringField())
2736

37+
connection_type = Connection
38+
2839
@resolve_only_args
2940
def resolve_climates(self):
3041
return [c.strip() for c in self.instance.climate.split(',')]
@@ -41,6 +52,8 @@ class Meta:
4152
class Film(DjangoNode):
4253
producers = graphene.ListField(graphene.StringField())
4354

55+
connection_type = Connection
56+
4457
@resolve_only_args
4558
def resolve_producers(self):
4659
return [c.strip() for c in self.instance.producer.split(',')]
@@ -57,6 +70,8 @@ class Specie(DjangoNode):
5770
hair_colors = graphene.ListField(graphene.StringField())
5871
skin_colors = graphene.ListField(graphene.StringField())
5972

73+
connection_type = Connection
74+
6075
@resolve_only_args
6176
def resolve_eye_colors(self):
6277
return [c.strip() for c in self.instance.eye_colors.split(',')]
@@ -79,6 +94,8 @@ class Vehicle(DjangoNode):
7994
'''A single transport craft that does not have hyperdrive capability'''
8095
manufacturers = graphene.ListField(graphene.StringField())
8196

97+
connection_type = Connection
98+
8299
@resolve_only_args
83100
def resolve_manufacturers(self):
84101
return [c.strip() for c in self.instance.manufacturer.split(',')]
@@ -92,6 +109,8 @@ class Starship(DjangoNode):
92109
'''A single transport craft that has hyperdrive capability.'''
93110
manufacturers = graphene.ListField(graphene.StringField())
94111

112+
connection_type = Connection
113+
95114
@resolve_only_args
96115
def resolve_manufacturers(self):
97116
return [c.strip() for c in self.instance.manufacturer.split(',')]

0 commit comments

Comments
 (0)
0