From 4897e0fcb7b124624681427c2929aea58fe8f844 Mon Sep 17 00:00:00 2001 From: Abhinav Sadhu Date: Mon, 4 Oct 2021 16:45:30 +0530 Subject: [PATCH 1/2] Ability to run subscriptions code snippet as it is Allows you to copy the snippet of code from this documentation and run it as is, without code changes. The "testing subscriptions" snippet has been updated for the same. --- docs/operations/testing.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/operations/testing.md b/docs/operations/testing.md index 8c9f0bdaad..0c30ca8253 100644 --- a/docs/operations/testing.md +++ b/docs/operations/testing.md @@ -102,6 +102,20 @@ async def test_mutaton(): And finally, a test for our [`count` Subscription](docs/general/subscriptions.md): ```python +import asyncio +import pytest as pytest +import strawberry + +@strawberry.type +class Subscription: + @strawberry.subscription + async def count(self, target: int = 100) -> int: + for i in range(target): + yield i + await asyncio.sleep(0.5) + +schema = strawberry.Schema(query=Query, subscription=Subscription) + @pytest.mark.asyncio async def test_subscription(): query = """ @@ -118,6 +132,7 @@ async def test_subscription(): assert result.data == {"count": index} index += 1 + ``` As you can see testing Subscriptions is a bit more complicated because we want to check From 592cdefc5306b2040adb29121f83eb970c4b5c6c Mon Sep 17 00:00:00 2001 From: Abhinav Sadhu Date: Mon, 4 Oct 2021 18:30:31 +0530 Subject: [PATCH 2/2] Create Query class + Fix styling Created Query class and also made the other requested changes on PR #1296 --- docs/operations/testing.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/operations/testing.md b/docs/operations/testing.md index 0c30ca8253..9de01422ca 100644 --- a/docs/operations/testing.md +++ b/docs/operations/testing.md @@ -103,7 +103,7 @@ And finally, a test for our [`count` Subscription](docs/general/subscriptions.md ```python import asyncio -import pytest as pytest +import pytest import strawberry @strawberry.type @@ -114,6 +114,12 @@ class Subscription: yield i await asyncio.sleep(0.5) +@strawberry.type +class Query: + @strawberry.field + def hello() -> str: + return "world" + schema = strawberry.Schema(query=Query, subscription=Subscription) @pytest.mark.asyncio @@ -132,7 +138,6 @@ async def test_subscription(): assert result.data == {"count": index} index += 1 - ``` As you can see testing Subscriptions is a bit more complicated because we want to check