-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathschema.py
More file actions
34 lines (24 loc) · 837 Bytes
/
schema.py
File metadata and controls
34 lines (24 loc) · 837 Bytes
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
import random
import asyncio
import graphene
class Query(graphene.ObjectType):
base = graphene.String()
class RandomType(graphene.ObjectType):
seconds = graphene.Int()
random_int = graphene.Int()
class Subscription(graphene.ObjectType):
count_seconds = graphene.Float(up_to=graphene.Int())
random_int = graphene.Field(RandomType)
async def resolve_count_seconds(root, info, up_to=5):
for i in range(up_to):
print("YIELD SECOND", i)
yield i
await asyncio.sleep(1.)
yield up_to
async def resolve_random_int(root, info):
i = 0
while True:
yield RandomType(seconds=i, random_int=random.randint(0, 500))
await asyncio.sleep(1.)
i += 1
schema = graphene.Schema(query=Query, subscription=Subscription)