From ee785d29a7922c6136c437bc8b2484d2b6170701 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Thu, 6 Aug 2020 21:02:35 +0100 Subject: [PATCH] Updated v3 release notes (markdown) --- v3-release-notes.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/v3-release-notes.md b/v3-release-notes.md index 5f5b804..9726ab6 100644 --- a/v3-release-notes.md +++ b/v3-release-notes.md @@ -63,6 +63,36 @@ assert result.data["color"] == "RED" Reference: https://github.com/graphql-python/graphene/pull/1153 +### Subscription support + +Graphene v3 add subscription support 🎉 Here is an example of it in action: + +```python +from graphene import ObjectType, Int, Schema + +class Subscription(ObjectType): + count_to_ten = Int() + + async def subscribe_count_to_ten(root, info): + count = 0 + while count < 10: + count += 1 + yield count + +class Query(ObjectType): + a = String() + +schema = Schema(query=Query, subscription=Subscription) + +result = await schema.subscribe("subscription { countToTen }") +count = 0 +async for item in result: + count = item.data["countToTen"] +assert count == 10 +``` + +**Note:** Using subscriptions with a server like Django or Flask still relies on the server supporting websockets. + ### Fast ObjectType creation In Graphene v3 optimises the ObjectType initialization resulting in a x3 speed up! It does this by leveraging the same strategy that dataclasses introduced (dynamic creation of optimal `__init__` functions based on eval).