Skip to content

Commit 0a395fe

Browse files
committed
Improved python syntax
1 parent d46e957 commit 0a395fe

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

examples/starwars/data.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
humanData = {}
2-
droidData = {}
1+
human_data = {}
2+
droid_data = {}
33

44

55
def setup():
66
from .schema import Human, Droid
7-
global humanData, droidData
7+
global human_data, droid_data
88
luke = Human(
99
id='1000',
1010
name='Luke Skywalker',
@@ -45,7 +45,7 @@ def setup():
4545
home_planet=None,
4646
)
4747

48-
humanData = {
48+
human_data = {
4949
'1000': luke,
5050
'1001': vader,
5151
'1002': han,
@@ -69,29 +69,29 @@ def setup():
6969
primary_function='Astromech',
7070
)
7171

72-
droidData = {
72+
droid_data = {
7373
'2000': threepio,
7474
'2001': artoo,
7575
}
7676

7777

78-
def getCharacter(id):
79-
return humanData.get(id) or droidData.get(id)
78+
def get_character(id):
79+
return human_data.get(id) or droid_data.get(id)
8080

8181

82-
def getFriends(character):
83-
return map(getCharacter, character.friends)
82+
def get_friends(character):
83+
return map(get_character, character.friends)
8484

8585

86-
def getHero(episode):
86+
def get_hero(episode):
8787
if episode == 5:
88-
return humanData['1000']
89-
return droidData['2001']
88+
return human_data['1000']
89+
return droid_data['2001']
9090

9191

92-
def getHuman(id):
93-
return humanData.get(id)
92+
def get_human(id):
93+
return human_data.get(id)
9494

9595

96-
def getDroid(id):
97-
return droidData.get(id)
96+
def get_droid(id):
97+
return droid_data.get(id)

examples/starwars/schema.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from graphene import resolve_only_args
33
from graphql.core.type import GraphQLEnumValue
44

5-
from .data import getCharacter, getDroid, getHero, getHuman
5+
from .data import get_character, get_droid, get_hero, get_human
66

77
Episode = graphene.Enum('Episode', dict(
88
NEWHOPE=GraphQLEnumValue(4),
@@ -19,7 +19,7 @@ class Character(graphene.Interface):
1919

2020
def resolve_friends(self, args, *_):
2121
# The character friends is a list of strings
22-
return [getCharacter(f) for f in self.friends]
22+
return [get_character(f) for f in self.friends]
2323

2424

2525
class Human(Character):
@@ -43,15 +43,15 @@ class Query(graphene.ObjectType):
4343

4444
@resolve_only_args
4545
def resolve_hero(self, episode=None):
46-
return getHero(episode)
46+
return get_hero(episode)
4747

4848
@resolve_only_args
4949
def resolve_human(self, id):
50-
return getHuman(id)
50+
return get_human(id)
5151

5252
@resolve_only_args
5353
def resolve_droid(self, id):
54-
return getDroid(id)
54+
return get_droid(id)
5555

5656

5757
Schema = graphene.Schema(query=Query)

0 commit comments

Comments
 (0)