Open bennnym opened 3 years ago
Hi @bennnym , thanks for the bug report.
I think the error happens because there is no support for context manager yet. Would you mind opening a PR to support it?
Otherwise I can take a look at this in few days.
Hi @ecthiender, I didn't realise it wasn't supported.
Why is it in the examples on the readme if it isn't?
@bennnym sorry I'm dumb. It is supported.
I tried this code (same as your code, adding missing variables) and it seems to work:
import time
from graphql_client import GraphQLClient
endpoint = 'ws://localhost:8080/graphql'
new_header = {
'authorization': 'secret'
}
subscription = """
subscription {
notifications {
id
title
content
}
}
"""
def callback(_id, data):
print("got new data..")
print(f"msg id: {_id}. data: {data}")
with GraphQLClient(endpoint) as client:
sub_id = client.subscribe(subscription,
# variables={'limit': 10},
headers=new_header,
callback=callback)
print('got sub id', sub_id)
time.sleep(2)
client.stop_subscribe(sub_id)
I get this output:
got sub id b48cfc9393ed46e099d7e7252155a965
got new data..
msg id: b48cfc9393ed46e099d7e7252155a965. data: {'type': 'error', 'id': 'b48cfc9393ed46e099d7e7252155a965', 'payload': {'errors': [{'extensions': {'code': 'validation-failed', 'path': '$.selectionSet.notifications'}, 'message': "field 'notifications' not found in type: 'subscription_root'"}]}}
got new data..
msg id: b48cfc9393ed46e099d7e7252155a965. data: {'type': 'complete', 'id': 'b48cfc9393ed46e099d7e7252155a965'}
running the simple example on the homepage
returns the following: