mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 03:23:55 +03:00
Added test relay schema
This commit is contained in:
parent
9a84d595a1
commit
cd216447c2
|
@ -1,7 +1,9 @@
|
|||
import graphene
|
||||
from graphene import resolve_only_args
|
||||
from graphene import resolve_only_args, relay
|
||||
|
||||
from .data import getHero, getHuman, getCharacter, getDroid, Human as _Human, Droid as _Droid
|
||||
from .data import (
|
||||
getHero, getHuman, getCharacter, getDroid,
|
||||
Human as _Human, Droid as _Droid)
|
||||
|
||||
Episode = graphene.Enum('Episode', dict(
|
||||
NEWHOPE=4,
|
||||
|
@ -9,39 +11,39 @@ Episode = graphene.Enum('Episode', dict(
|
|||
JEDI=6
|
||||
))
|
||||
|
||||
|
||||
def wrap_character(character):
|
||||
if isinstance(character, _Human):
|
||||
return Human(character)
|
||||
elif isinstance(character, _Droid):
|
||||
return Droid(character)
|
||||
|
||||
|
||||
class Character(graphene.Interface):
|
||||
id = graphene.IDField()
|
||||
name = graphene.StringField()
|
||||
friends = graphene.ListField('self')
|
||||
friends = relay.Connection('self')
|
||||
appearsIn = graphene.ListField(Episode)
|
||||
|
||||
def resolve_friends(self, args, *_):
|
||||
return [wrap_character(getCharacter(f)) for f in self.instance.friends]
|
||||
|
||||
class Human(Character):
|
||||
|
||||
class Human(relay.Node, Character):
|
||||
homePlanet = graphene.StringField()
|
||||
|
||||
|
||||
class Droid(Character):
|
||||
class Droid(relay.Node, Character):
|
||||
primaryFunction = graphene.StringField()
|
||||
|
||||
|
||||
class Query(graphene.ObjectType):
|
||||
hero = graphene.Field(Character,
|
||||
episode = graphene.Argument(Episode)
|
||||
)
|
||||
episode=graphene.Argument(Episode))
|
||||
human = graphene.Field(Human,
|
||||
id = graphene.Argument(graphene.String)
|
||||
)
|
||||
id=graphene.Argument(graphene.String))
|
||||
droid = graphene.Field(Droid,
|
||||
id = graphene.Argument(graphene.String)
|
||||
)
|
||||
id=graphene.Argument(graphene.String))
|
||||
node = graphene.Field(relay.Node)
|
||||
|
||||
@resolve_only_args
|
||||
def resolve_hero(self, episode):
|
||||
|
@ -50,8 +52,6 @@ class Query(graphene.ObjectType):
|
|||
@resolve_only_args
|
||||
def resolve_human(self, id):
|
||||
return wrap_character(getHuman(id))
|
||||
if human:
|
||||
return Human(human)
|
||||
|
||||
@resolve_only_args
|
||||
def resolve_droid(self, id):
|
||||
|
|
Loading…
Reference in New Issue
Block a user