Commit ae93fd90 authored by Andrii Zarubin's avatar Andrii Zarubin

Add order create mutation

parent 99fed405
import graphene
from graphene_django.debug import DjangoDebug
from graphqltest.orders.schema import OrderQuery
from graphqltest.orders.schema import OrderQuery, OrderMutation
class Query(graphene.ObjectType, OrderQuery):
class Query(OrderQuery, graphene.ObjectType):
debug = graphene.Field(DjangoDebug, name='__debug')
schema = graphene.Schema(query=Query)
class Mutation(OrderMutation, graphene.ObjectType):
schema = graphene.Schema(query=Query, mutation=Mutation)
No preview for this file type
from graphene.types.abstracttype import AbstractType
from graphene.types.argument import Argument
from graphene.types.field import Field
from graphene.types.mutation import Mutation
from graphene_django.filter.fields import DjangoFilterConnectionField
from graphene_django.types import DjangoObjectType
from graphqltest.core.schema import DjangoNode
from graphqltest.core.schema import DjangoNode, DjangoInputObjectType
from .models import Order
class OrderInput(DjangoInputObjectType):
class Meta:
model = Order
exclude_fields = ('id',)
class OrderNode(DjangoObjectType):
class Meta:
model = Order
interfaces = (DjangoNode,)
class CreateOrderMutation(Mutation):
order = Field(OrderNode)
class Input:
order = Argument(OrderInput)
def mutate(root, args, request, info):
order_args = args.pop('order')
order = Order.objects.create(**order_args)
return CreateOrderMutation(order=order)
class OrderMutation(AbstractType):
create_order = CreateOrderMutation.Field()
class OrderQuery(AbstractType):
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment