Skip to content

Commit

Permalink
Ability to run subscriptions code snippet as it is (#1296)
Browse files Browse the repository at this point in the history
* 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.

* Create Query class + Fix styling

Created Query class and also made the other requested changes on PR #1296
  • Loading branch information
sighclone authored Oct 4, 2021
1 parent 50684a7 commit b4cc757
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/operations/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ async def test_mutaton():
And finally, a test for our [`count` Subscription](docs/general/subscriptions.md):

```python
import asyncio
import 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)

@strawberry.type
class Query:
@strawberry.field
def hello() -> str:
return "world"

schema = strawberry.Schema(query=Query, subscription=Subscription)

@pytest.mark.asyncio
async def test_subscription():
query = """
Expand Down

0 comments on commit b4cc757

Please sign in to comment.