graphene/examples/starwars_relay/data.py

72 lines
1.6 KiB
Python
Raw Normal View History

2015-10-27 09:54:51 +03:00
data = {}
def setup():
global data
2015-10-27 09:54:51 +03:00
from .schema import Ship, Faction
xwing = Ship(id="1", name="X-Wing")
2015-10-27 09:54:51 +03:00
ywing = Ship(id="2", name="Y-Wing")
awing = Ship(id="3", name="A-Wing")
2015-10-27 09:54:51 +03:00
# Yeah, technically it's Corellian. But it flew in the service of the rebels,
# so for the purposes of this demo it's a rebel ship.
falcon = Ship(id="4", name="Millenium Falcon")
2015-10-27 09:54:51 +03:00
homeOne = Ship(id="5", name="Home One")
2015-10-27 09:54:51 +03:00
tieFighter = Ship(id="6", name="TIE Fighter")
2015-10-27 09:54:51 +03:00
tieInterceptor = Ship(id="7", name="TIE Interceptor")
2015-10-27 09:54:51 +03:00
executor = Ship(id="8", name="Executor")
2015-10-27 09:54:51 +03:00
rebels = Faction(
id="1", name="Alliance to Restore the Republic", ships=["1", "2", "3", "4", "5"]
2015-10-27 09:54:51 +03:00
)
empire = Faction(id="2", name="Galactic Empire", ships=["6", "7", "8"])
2015-10-27 09:54:51 +03:00
data = {
"Faction": {"1": rebels, "2": empire},
"Ship": {
"1": xwing,
"2": ywing,
"3": awing,
"4": falcon,
"5": homeOne,
"6": tieFighter,
"7": tieInterceptor,
"8": executor,
2015-10-27 09:54:51 +03:00
},
2015-09-26 09:25:10 +03:00
}
2015-10-03 08:17:51 +03:00
2015-10-30 10:36:31 +03:00
def create_ship(ship_name, faction_id):
from .schema import Ship
next_ship = len(data["Ship"].keys()) + 1
new_ship = Ship(id=str(next_ship), name=ship_name)
data["Ship"][new_ship.id] = new_ship
data["Faction"][faction_id].ships.append(new_ship.id)
2015-10-30 10:36:31 +03:00
return new_ship
2015-09-26 09:25:10 +03:00
2015-10-30 10:36:31 +03:00
def get_ship(_id):
return data["Ship"][_id]
2015-09-26 09:25:10 +03:00
2015-10-03 08:17:51 +03:00
2015-10-30 10:36:31 +03:00
def get_faction(_id):
return data["Faction"][_id]
2015-09-26 09:25:10 +03:00
2015-10-03 08:17:51 +03:00
2015-10-30 10:36:31 +03:00
def get_rebels():
return get_faction("1")
2015-09-26 09:25:10 +03:00
2015-10-03 08:17:51 +03:00
2015-10-30 10:36:31 +03:00
def get_empire():
return get_faction("2")