A dead-simple GraphQL client that supports subscriptions over websockets
Project description
py-graphql-client
Dead-simple to use GraphQL client over websocket. Using the apollo-transport-ws protocol.
Install
pip install py-graphql-client
Examples
Setup subscriptions super easily
from graphql_client import GraphQLClient
ws = GraphQLClient('ws://localhost:8080/graphql')
def callback(_id, data):
print("got new data..")
print(f"msg id: {_id}. data: {data}")
query = """
subscription {
notifications {
id
title
content
}
}
"""
sub_id = ws.subscribe(query, callback=callback)
...
# later stop the subscription
ws.stop_subscribe(sub_id)
ws.close()
Variables can be passed
from graphql_client import GraphQLClient
ws = GraphQLClient('ws://localhost:8080/graphql')
def callback(_id, data):
print("got new data..")
print(f"msg id: {_id}. data: {data}")
query = """
subscription ($limit: Int!) {
notifications (order_by: {created: "desc"}, limit: $limit) {
id
title
content
}
}
"""
sub_id = ws.subscribe(query, variables={'limit': 10}, callback=callback)
Normal queries and mutations work too
from graphql_client import GraphQLClient
ws = GraphQLClient('ws://localhost:8080/graphql')
query = """
query ($limit: Int!) {
notifications (order_by: {created: "desc"}, limit: $limit) {
id
title
content
}
}
"""
res = ws.query(query, variables={'limit': 10})
print(res)
ws.close()
TODO
- tests
- support http as well
- should use asyncio websocket library?
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for py-graphql-client-0.1.1b2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d68211a29c0e5f3d4c17a222df397542811b882577c3e85f683064dfdff2698e |
|
MD5 | 2c331fec0d2aa5651ad84b7a219cf00c |
|
BLAKE2b-256 | 0927e30c9085de5e1449edad7514aac5a5f687a440ed2067262fc8d6ebecb5ef |
Close
Hashes for py_graphql_client-0.1.1b2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8de02f95fc5463946c96dbeb003af2f6d0f61f3bb6c7e5acf32961a6d073a90 |
|
MD5 | 7d6430e28c26fc1e10f095bf28abdd11 |
|
BLAKE2b-256 | 2e1aebe076b4acbae6bd56c93b9f1714b6f32cc9c07fc5fffd0fb3fd8ba1856b |