graphene/tests/starwars_django/schema.py
2015-09-29 23:40:40 -07:00

49 lines
998 B
Python

import graphene
from graphene import resolve_only_args, relay
from graphene.contrib.django import (
DjangoObjectType,
DjangoNode
)
from .models import Ship as ShipModel, Faction as FactionModel
from .data import (
getFaction,
getShip,
getRebels,
getEmpire,
)
schema = graphene.Schema(name='Starwars Django Relay Schema')
class Ship(DjangoNode):
class Meta:
model = ShipModel
@classmethod
def get_node(cls, id):
return Ship(getShip(id))
class Faction(DjangoNode):
class Meta:
model = FactionModel
@classmethod
def get_node(cls, id):
return Faction(getFaction(id))
class Query(graphene.ObjectType):
rebels = graphene.Field(Faction)
empire = graphene.Field(Faction)
node = relay.NodeField()
@resolve_only_args
def resolve_rebels(self):
return Faction(getRebels())
@resolve_only_args
def resolve_empire(self):
return Faction(getEmpire())
schema.query = Query