-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.py
More file actions
70 lines (58 loc) · 1.81 KB
/
Copy pathschema.py
File metadata and controls
70 lines (58 loc) · 1.81 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
65
66
67
68
69
70
# A test demo graphene app to learn/understand the graphene library
import graphene
import json
from datetime import date, datetime
class User(graphene.ObjectType):
id = graphene.ID()
username = graphene.String()
password = graphene.String()
email = graphene.String()
dateCreated = graphene.DateTime()
dateOfBirth = graphene.DateTime()
class Query(graphene.ObjectType):
users = graphene.List(User)
def resolve_users(self, info):
return [
User(
id=1,
username='Aerith',
password='badPassword',
email='Aerith@company.com',
dateCreated=datetime.now(),
dateOfBirth=date(1985,2,7)
)
]
class CreateUser(graphene.Mutation):
class Arguments:
username = graphene.String()
password = graphene.String()
email = graphene.String()
dateOfBirth = graphene.Date()
user = graphene.Field(User)
def mutate(self, info, username, password, email, dateOfBirth):
user = User(username=username, password=password, email=email, dateOfBirth=dateOfBirth)
return CreateUser(user=user)
class Mutations(graphene.ObjectType):
createUser = CreateUser.Field()
schema = graphene.Schema(query=Query, mutation=Mutations)
result = schema.execute(
'''
mutation createUser {
createUser(
username: "Aerith",
password: "badPassword",
email:"A@gmail.com",
dateOfBirth:"1989-02-08"
){
user {
username
password
email
dateOfBirth
}
}
}
'''
)
items = dict(result.data.items())
print(json.dumps(items, indent=4))