Compare commits
No commits in common. "6e4dd4bf9697a02f8b094e3294531699ad45a576" and "f0ac07dc6d4047d31fbe84e17c2aaa34765c39c8" have entirely different histories.
6e4dd4bf96
...
f0ac07dc6d
|
@ -1 +0,0 @@
|
||||||
from .game import Mutation as GameMutation
|
|
|
@ -1,29 +0,0 @@
|
||||||
import graphene
|
|
||||||
|
|
||||||
from games.graphql.types import Game
|
|
||||||
from games.models import Game as GameModel
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateGameMutation(graphene.Mutation):
|
|
||||||
class Arguments:
|
|
||||||
id = graphene.ID(required=True)
|
|
||||||
name = graphene.String()
|
|
||||||
year_released = graphene.Int()
|
|
||||||
wikidata = graphene.String()
|
|
||||||
|
|
||||||
game = graphene.Field(Game)
|
|
||||||
|
|
||||||
def mutate(self, info, id, name=None, year_released=None, wikidata=None):
|
|
||||||
game_instance = GameModel.objects.get(pk=id)
|
|
||||||
if name is not None:
|
|
||||||
game_instance.name = name
|
|
||||||
if year_released is not None:
|
|
||||||
game_instance.year_released = year_released
|
|
||||||
if wikidata is not None:
|
|
||||||
game_instance.wikidata = wikidata
|
|
||||||
game_instance.save()
|
|
||||||
return UpdateGameMutation(game=game_instance)
|
|
||||||
|
|
||||||
|
|
||||||
class Mutation(graphene.ObjectType):
|
|
||||||
update_game = UpdateGameMutation.Field()
|
|
|
@ -1,6 +0,0 @@
|
||||||
from .device import Query as DeviceQuery
|
|
||||||
from .edition import Query as EditionQuery
|
|
||||||
from .game import Query as GameQuery
|
|
||||||
from .platform import Query as PlatformQuery
|
|
||||||
from .purchase import Query as PurchaseQuery
|
|
||||||
from .session import Query as SessionQuery
|
|
|
@ -1,11 +0,0 @@
|
||||||
import graphene
|
|
||||||
|
|
||||||
from games.graphql.types import Device
|
|
||||||
from games.models import Device as DeviceModel
|
|
||||||
|
|
||||||
|
|
||||||
class Query(graphene.ObjectType):
|
|
||||||
devices = graphene.List(Device)
|
|
||||||
|
|
||||||
def resolve_devices(self, info, **kwargs):
|
|
||||||
return DeviceModel.objects.all()
|
|
|
@ -1,11 +0,0 @@
|
||||||
import graphene
|
|
||||||
|
|
||||||
from games.graphql.types import Edition
|
|
||||||
from games.models import Game as EditionModel
|
|
||||||
|
|
||||||
|
|
||||||
class Query(graphene.ObjectType):
|
|
||||||
editions = graphene.List(Edition)
|
|
||||||
|
|
||||||
def resolve_editions(self, info, **kwargs):
|
|
||||||
return EditionModel.objects.all()
|
|
|
@ -1,18 +0,0 @@
|
||||||
import graphene
|
|
||||||
|
|
||||||
from games.graphql.types import Game
|
|
||||||
from games.models import Game as GameModel
|
|
||||||
|
|
||||||
|
|
||||||
class Query(graphene.ObjectType):
|
|
||||||
games = graphene.List(Game)
|
|
||||||
game_by_name = graphene.Field(Game, name=graphene.String(required=True))
|
|
||||||
|
|
||||||
def resolve_games(self, info, **kwargs):
|
|
||||||
return GameModel.objects.all()
|
|
||||||
|
|
||||||
def resolve_game_by_name(self, info, name):
|
|
||||||
try:
|
|
||||||
return GameModel.objects.get(name=name)
|
|
||||||
except GameModel.DoesNotExist:
|
|
||||||
return None
|
|
|
@ -1,11 +0,0 @@
|
||||||
import graphene
|
|
||||||
|
|
||||||
from games.graphql.types import Platform
|
|
||||||
from games.models import Platform as PlatformModel
|
|
||||||
|
|
||||||
|
|
||||||
class Query(graphene.ObjectType):
|
|
||||||
platforms = graphene.List(Platform)
|
|
||||||
|
|
||||||
def resolve_platforms(self, info, **kwargs):
|
|
||||||
return PlatformModel.objects.all()
|
|
|
@ -1,11 +0,0 @@
|
||||||
import graphene
|
|
||||||
|
|
||||||
from games.graphql.types import Purchase
|
|
||||||
from games.models import Purchase as PurchaseModel
|
|
||||||
|
|
||||||
|
|
||||||
class Query(graphene.ObjectType):
|
|
||||||
purchases = graphene.List(Purchase)
|
|
||||||
|
|
||||||
def resolve_purchases(self, info, **kwargs):
|
|
||||||
return PurchaseModel.objects.all()
|
|
|
@ -1,11 +0,0 @@
|
||||||
import graphene
|
|
||||||
|
|
||||||
from games.graphql.types import Session
|
|
||||||
from games.models import Session as SessionModel
|
|
||||||
|
|
||||||
|
|
||||||
class Query(graphene.ObjectType):
|
|
||||||
sessions = graphene.List(Session)
|
|
||||||
|
|
||||||
def resolve_sessions(self, info, **kwargs):
|
|
||||||
return SessionModel.objects.all()
|
|
|
@ -1,44 +0,0 @@
|
||||||
from graphene_django import DjangoObjectType
|
|
||||||
|
|
||||||
from games.models import Device as DeviceModel
|
|
||||||
from games.models import Edition as EditionModel
|
|
||||||
from games.models import Game as GameModel
|
|
||||||
from games.models import Platform as PlatformModel
|
|
||||||
from games.models import Purchase as PurchaseModel
|
|
||||||
from games.models import Session as SessionModel
|
|
||||||
|
|
||||||
|
|
||||||
class Game(DjangoObjectType):
|
|
||||||
class Meta:
|
|
||||||
model = GameModel
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class Edition(DjangoObjectType):
|
|
||||||
class Meta:
|
|
||||||
model = EditionModel
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class Purchase(DjangoObjectType):
|
|
||||||
class Meta:
|
|
||||||
model = PurchaseModel
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class Session(DjangoObjectType):
|
|
||||||
class Meta:
|
|
||||||
model = SessionModel
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class Platform(DjangoObjectType):
|
|
||||||
class Meta:
|
|
||||||
model = PlatformModel
|
|
||||||
fields = "__all__"
|
|
||||||
|
|
||||||
|
|
||||||
class Device(DjangoObjectType):
|
|
||||||
class Meta:
|
|
||||||
model = DeviceModel
|
|
||||||
fields = "__all__"
|
|
|
@ -1,30 +1,82 @@
|
||||||
import graphene
|
import graphene
|
||||||
|
from graphene_django import DjangoObjectType
|
||||||
|
|
||||||
from games.graphql.mutations import GameMutation
|
from .models import Device as DeviceModel
|
||||||
from games.graphql.queries import (
|
from .models import Edition as EditionModel
|
||||||
DeviceQuery,
|
from .models import Game as GameModel
|
||||||
EditionQuery,
|
from .models import Platform as PlatformModel
|
||||||
GameQuery,
|
from .models import Purchase as PurchaseModel
|
||||||
PlatformQuery,
|
from .models import Session as SessionModel
|
||||||
PurchaseQuery,
|
|
||||||
SessionQuery,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Query(
|
class Game(DjangoObjectType):
|
||||||
GameQuery,
|
class Meta:
|
||||||
EditionQuery,
|
model = GameModel
|
||||||
DeviceQuery,
|
fields = "__all__"
|
||||||
PlatformQuery,
|
|
||||||
PurchaseQuery,
|
|
||||||
SessionQuery,
|
|
||||||
graphene.ObjectType,
|
|
||||||
):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Mutation(GameMutation, graphene.ObjectType):
|
class Edition(DjangoObjectType):
|
||||||
pass
|
class Meta:
|
||||||
|
model = EditionModel
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
schema = graphene.Schema(query=Query, mutation=Mutation)
|
class Purchase(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = PurchaseModel
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class Session(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = SessionModel
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class Platform(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = PlatformModel
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class Device(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
model = DeviceModel
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class Query(graphene.ObjectType):
|
||||||
|
games = graphene.List(Game)
|
||||||
|
game_by_name = graphene.Field(Game, name=graphene.String(required=True))
|
||||||
|
purchases = graphene.List(Purchase)
|
||||||
|
editions = graphene.List(Edition)
|
||||||
|
sessions = graphene.List(Session)
|
||||||
|
platforms = graphene.List(Platform)
|
||||||
|
devices = graphene.List(Device)
|
||||||
|
|
||||||
|
def resolve_games(self, info, **kwargs):
|
||||||
|
return GameModel.objects.all()
|
||||||
|
|
||||||
|
def resolve_game_by_name(self, info, name):
|
||||||
|
try:
|
||||||
|
return GameModel.objects.get(name=name)
|
||||||
|
except GameModel.DoesNotExist:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def resolve_editions(self, info, **kwargs):
|
||||||
|
return EditionModel.objects.all()
|
||||||
|
|
||||||
|
def resolve_purchases(self, info, **kwargs):
|
||||||
|
return PurchaseModel.objects.all()
|
||||||
|
|
||||||
|
def resolve_sessions(self, info, **kwargs):
|
||||||
|
return SessionModel.objects.all()
|
||||||
|
|
||||||
|
def resolve_platforms(self, info, **kwargs):
|
||||||
|
return PlatformModel.objects.all()
|
||||||
|
|
||||||
|
def resolve_devices(self, info, **kwargs):
|
||||||
|
return DeviceModel.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
schema = graphene.Schema(query=Query)
|
||||||
|
|
Loading…
Reference in New Issue