Skip to content

Commit 774db0f

Browse files
committed
Update usage docs
1 parent 5ceaae0 commit 774db0f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pip install python-graphql-client
1616

1717
## Usage
1818

19+
- Query/Mutation
20+
1921
```python
2022
from python_graphql_client import GraphqlClient
2123

@@ -45,6 +47,31 @@ data = asyncio.run(client.execute_async(query=query, variables=variables))
4547
print(data) # => {'data': {'country': {'code': 'CA', 'name': 'Canada'}}}
4648
```
4749

50+
- Subscription
51+
52+
```python
53+
from python_graphql_client import GraphqlClient
54+
55+
# Instantiate the client with a websocket endpoint.
56+
client = GraphqlClient(endpoint="wss://www.your-api.com/graphql")
57+
58+
# Create the query string and variables required for the request.
59+
query = """
60+
subscription onMessageAdded {
61+
messageAdded
62+
}
63+
"""
64+
65+
# Asynchronous request
66+
import asyncio
67+
68+
asyncio.run(client.subscribe(query=query, handle=print))
69+
# => {'data': {'messageAdded': 'Error omnis quis.'}}
70+
# => {'data': {'messageAdded': 'Enim asperiores omnis.'}}
71+
# => {'data': {'messageAdded': 'Unde ullam consequatur quam eius vel.'}}
72+
# ...
73+
```
74+
4875
## Roadmap
4976

5077
To start we'll try and use a Github project board for listing current work and updating priorities of upcoming features.

0 commit comments

Comments
 (0)