File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 1
1
"""Module containing graphQL client."""
2
2
import json
3
+ import logging
3
4
from typing import Callable
4
5
5
6
import aiohttp
6
7
import requests
7
8
import websockets
8
9
10
+ logging .basicConfig (level = logging .INFO , format = "%(levelname)s:%(message)s" )
11
+
9
12
10
13
class GraphqlClient :
11
14
"""Class which represents the interface to make graphQL requests through."""
@@ -79,6 +82,8 @@ async def subscribe(
79
82
headers : dict = None ,
80
83
):
81
84
"""Make asynchronous request for GraphQL subscription."""
85
+ connection_init_message = json .dumps ({"type" : "connection_init" , "payload" : {}})
86
+
82
87
request_body = self .__request_body (
83
88
query = query , variables = variables , operation_name = operation_name
84
89
)
@@ -89,7 +94,11 @@ async def subscribe(
89
94
async with websockets .connect (
90
95
self .endpoint , subprotocols = ["graphql-ws" ]
91
96
) as websocket :
97
+ await websocket .send (connection_init_message )
92
98
await websocket .send (request_message )
93
99
async for response_message in websocket :
94
100
response_body = json .loads (response_message )
95
- handle (response_body ["payload" ])
101
+ if response_body ["type" ] == "connection_ack" :
102
+ logging .info ("the server accepted the connection" )
103
+ else :
104
+ handle (response_body ["payload" ])
You can’t perform that action at this time.
0 commit comments