mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
Improved syntax in starwars
This commit is contained in:
parent
e9cf8616ba
commit
d2dc25cc07
|
@ -9,21 +9,24 @@ Episode = graphene.Enum('Episode', dict(
|
||||||
JEDI = 6
|
JEDI = 6
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
def wrap_character(character):
|
def wrap_character(character):
|
||||||
if isinstance(character, _Human):
|
if isinstance(character, _Human):
|
||||||
return Human(character)
|
return Human(character)
|
||||||
elif isinstance(character, _Droid):
|
elif isinstance(character, _Droid):
|
||||||
return Droid(character)
|
return Droid(character)
|
||||||
|
|
||||||
|
|
||||||
class Character(graphene.Interface):
|
class Character(graphene.Interface):
|
||||||
id = graphene.IDField()
|
id = graphene.IDField()
|
||||||
name = graphene.StringField()
|
name = graphene.StringField()
|
||||||
friends = graphene.ListField('Character')
|
friends = graphene.ListField('self')
|
||||||
appearsIn = graphene.ListField(Episode)
|
appearsIn = graphene.ListField(Episode)
|
||||||
|
|
||||||
def resolve_friends(self, args, *_):
|
def resolve_friends(self, args, *_):
|
||||||
return [wrap_character(getCharacter(f)) for f in self.instance.friends]
|
return [wrap_character(getCharacter(f)) for f in self.instance.friends]
|
||||||
|
|
||||||
|
|
||||||
class Human(Character):
|
class Human(Character):
|
||||||
homePlanet = graphene.StringField()
|
homePlanet = graphene.StringField()
|
||||||
|
|
||||||
|
@ -50,8 +53,6 @@ class Query(graphene.ObjectType):
|
||||||
@resolve_only_args
|
@resolve_only_args
|
||||||
def resolve_human(self, id):
|
def resolve_human(self, id):
|
||||||
return wrap_character(getHuman(id))
|
return wrap_character(getHuman(id))
|
||||||
if human:
|
|
||||||
return Human(human)
|
|
||||||
|
|
||||||
@resolve_only_args
|
@resolve_only_args
|
||||||
def resolve_droid(self, id):
|
def resolve_droid(self, id):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user