11import graphene
2- from graphene_django import DjangoObjectType
2+ from graphene .relay import Node
3+ from graphene_mongo .fields import MongoengineConnectionField
4+ from .models import Shop
5+ from .types import BikeType , ShopType
6+ from .mutations import CreateBikeMutation , UpdateBikeMutation , DeleteBikeMutation
37
4- from .models import UserModel
58
6- class UserType (DjangoObjectType ):
7- class Meta :
8- model = UserModel
9+ class Mutations (graphene .ObjectType ):
10+ create_bike = CreateBikeMutation .Field ()
11+ update_bike = UpdateBikeMutation .Field ()
12+ delete_bike = DeleteBikeMutation .Field ()
913
10- class Query (graphene .ObjectType ):
11- users = graphene .List (UserType )
12-
13- def resolve_users (self , info ):
14- return UserModel .objects .all ()
15-
16-
17- class CreateUser (graphene .Mutation ):
18- # id = graphene.Int()
19- first_name = graphene .String ()
20- last_name = graphene .String ()
2114
22- class Arguments :
23- first_name = graphene .String ()
24- last_name = graphene .String ()
25-
26- def mutate (self , info , first_name , last_name ):
27- user = UserModel (first_name = first_name , last_name = last_name )
28- user .save ()
29-
30- return CreateUser (
31- # id=user._id,
32- first_name = user .first_name ,
33- last_name = user .last_name ,
34- )
15+ class Query (graphene .ObjectType ):
16+ node = Node .Field ()
17+ bikes = MongoengineConnectionField (BikeType )
18+ shop_list = graphene .List (ShopType )
3519
20+ def resolve_shop_list (self , info ):
21+ return Shop .objects .all ()
3622
37- class Mutation (graphene .ObjectType ):
38- create_user = CreateUser .Field ()
3923
40- schema = graphene .Schema (query = Query , mutation = Mutation )
24+ schema = graphene .Schema (query = Query , mutation = Mutations , types = [ BikeType , ShopType ] )
0 commit comments