-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathschema_user.py
More file actions
65 lines (43 loc) · 1.39 KB
/
Copy pathschema_user.py
File metadata and controls
65 lines (43 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# coding:utf-8
# @Time :1/2/19 09:02
from database.model_user import ModelUser
from graphene_mongo.types import MongoengineObjectType
import graphene
from datetime import datetime
class UserAttribute:
id = graphene.String()
_in_time = graphene.String()
_utime = graphene.String()
nickname = graphene.String()
photo = graphene.String()
sex = graphene.String()
delete_flag = graphene.Int()
class User(MongoengineObjectType):
class Meta:
model = ModelUser
class UserNode(MongoengineObjectType):
class Meta:
model = ModelUser
interfaces = (graphene.relay.Node, )
class CreateUserInput(graphene.InputObjectType, UserAttribute):
pass
class CreateUser(graphene.Mutation):
user = graphene.Field(lambda: UserNode)
class Arguments:
input = CreateUserInput(required=True)
def mutate(self, info, input):
user = ModelUser(**input)
user.save()
return CreateUser(user=user)
class UpdateUser(graphene.Mutation):
user = graphene.Field(lambda: UserNode)
class Arguments:
input = CreateUserInput(required=True)
def mutate(self, info, input):
id = input.pop("id")
user = ModelUser.objects.get(id=id)
user._utime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
user.update(**input)
user.save()
return UpdateUser(user=user)