Add room mutation
This commit is contained in:
parent
e94c7c5e8a
commit
fe59a65e87
1
Pipfile
1
Pipfile
|
|
@ -23,6 +23,7 @@ raven = "==6.9.0"
|
||||||
django-extensions = "==1.9.8"
|
django-extensions = "==1.9.8"
|
||||||
graphene-django = "==2.2.0"
|
graphene-django = "==2.2.0"
|
||||||
django-filter = "==2.0.0"
|
django-filter = "==2.0.0"
|
||||||
|
djangorestframework = "==3.8.2"
|
||||||
pillow = "==5.0.0"
|
pillow = "==5.0.0"
|
||||||
wagtail = "==2.2.2"
|
wagtail = "==2.2.2"
|
||||||
django-cors-headers = "==2.2.0"
|
django-cors-headers = "==2.2.0"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"hash": {
|
"hash": {
|
||||||
"sha256": "22744fc51ea36160ffcfa7253af7639a5290f7fd6f0a28a07752bd2904e8b39f"
|
"sha256": "2341eacc0bfdcc8c231c5ebf696c89360052a264240118f3b509c927aeaf611b"
|
||||||
},
|
},
|
||||||
"pipfile-spec": 6,
|
"pipfile-spec": 6,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
|
@ -168,7 +168,7 @@
|
||||||
"sha256:b6714c3e4b0f8d524f193c91ecf5f5450092c2145439ac2769711f7eba89a9d9",
|
"sha256:b6714c3e4b0f8d524f193c91ecf5f5450092c2145439ac2769711f7eba89a9d9",
|
||||||
"sha256:c375e4f95a3a64fccac412e36fb42ba36881e52313ec021ef410b40f67cddca4"
|
"sha256:c375e4f95a3a64fccac412e36fb42ba36881e52313ec021ef410b40f67cddca4"
|
||||||
],
|
],
|
||||||
"markers": "python_version >= '2.7' and python_version != '3.3.*' and python_version != '3.2.*' and python_version != '3.1.*' and python_version != '3.0.*'",
|
"index": "pypi",
|
||||||
"version": "==3.8.2"
|
"version": "==3.8.2"
|
||||||
},
|
},
|
||||||
"docutils": {
|
"docutils": {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
mutation AddRoomMutation($input: RoomMutationInput!) {
|
||||||
|
room(input: $input) {
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
slug,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
appearance,
|
||||||
|
clientMutationId,
|
||||||
|
errors {
|
||||||
|
field
|
||||||
|
messages
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#{
|
||||||
|
# "input": {
|
||||||
|
# "title": "Neuer Raum",
|
||||||
|
# "description": "So eine Beschreibung",
|
||||||
|
# "userGroup": 4
|
||||||
|
#}
|
||||||
|
#}
|
||||||
|
|
@ -9,7 +9,7 @@ from api import graphene_wagtail
|
||||||
from book.schema.mutations import BookMutations
|
from book.schema.mutations import BookMutations
|
||||||
from filteredbook.schema import BookQuery
|
from filteredbook.schema import BookQuery
|
||||||
from objectives.schema import ObjectivesQuery
|
from objectives.schema import ObjectivesQuery
|
||||||
from rooms.schema import RoomsQuery
|
from rooms.schema import RoomsQuery, RoomMutations
|
||||||
from user.schema import UsersQuery
|
from user.schema import UsersQuery
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ class Query(UsersQuery, RoomsQuery, ObjectivesQuery, BookQuery, graphene.ObjectT
|
||||||
debug = graphene.Field(DjangoDebug, name='__debug')
|
debug = graphene.Field(DjangoDebug, name='__debug')
|
||||||
|
|
||||||
|
|
||||||
class Mutation(graphene.ObjectType, BookMutations):
|
class Mutation(BookMutations, RoomMutations, graphene.ObjectType):
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
debug = graphene.Field(DjangoDebug, name='__debug')
|
debug = graphene.Field(DjangoDebug, name='__debug')
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@ import graphene
|
||||||
from graphene import relay
|
from graphene import relay
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
from graphene_django.filter import DjangoFilterConnectionField
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
|
from graphene_django.rest_framework.mutation import SerializerMutation
|
||||||
|
|
||||||
from rooms.models import Room, RoomEntry
|
from rooms.models import Room, RoomEntry
|
||||||
|
from rooms.serializers import RoomSerializer
|
||||||
from user.schema import UserNode
|
from user.schema import UserNode
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -37,18 +39,17 @@ class RoomNode(DjangoObjectType):
|
||||||
|
|
||||||
|
|
||||||
class RoomsQuery(object):
|
class RoomsQuery(object):
|
||||||
room = graphene.Field(RoomNode, slug=graphene.String(), id=graphene.Int(), appearance=graphene.String())
|
room = relay.Node.Field(RoomNode)
|
||||||
room_entry = relay.Node.Field(RoomEntryNode)
|
room_entry = relay.Node.Field(RoomEntryNode)
|
||||||
|
|
||||||
all_rooms = DjangoFilterConnectionField(RoomNode)
|
all_rooms = DjangoFilterConnectionField(RoomNode)
|
||||||
all_room_entries = DjangoFilterConnectionField(RoomEntryNode)
|
all_room_entries = DjangoFilterConnectionField(RoomEntryNode)
|
||||||
|
|
||||||
def resolve_room(self, info, **kwargs):
|
|
||||||
slug = kwargs.get('slug')
|
|
||||||
room_id = kwargs.get('id')
|
|
||||||
|
|
||||||
if room_id is not None:
|
class RoomMutation(SerializerMutation):
|
||||||
return Room.objects.get(pk=room_id)
|
class Meta:
|
||||||
if slug is not None:
|
serializer_class = RoomSerializer
|
||||||
return Room.objects.get(slug=slug)
|
|
||||||
return None
|
|
||||||
|
class RoomMutations:
|
||||||
|
room = RoomMutation.Field()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from rooms.models import Room
|
||||||
|
|
||||||
|
|
||||||
|
class RoomSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Room
|
||||||
|
fields = ('id', 'title', 'description', 'slug', 'user_group', 'appearance', )
|
||||||
|
read_only_fields = ('id', 'slug', )
|
||||||
Loading…
Reference in New Issue