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 11"""Module containing graphQL client."""
22import json
3+ import logging
34from typing import Callable
45
56import aiohttp
67import requests
78import websockets
89
10+ logging .basicConfig (level = logging .INFO , format = "%(levelname)s:%(message)s" )
11+
912
1013class GraphqlClient :
1114 """Class which represents the interface to make graphQL requests through."""
@@ -79,6 +82,8 @@ async def subscribe(
7982 headers : dict = None ,
8083 ):
8184 """Make asynchronous request for GraphQL subscription."""
85+ connection_init_message = json .dumps ({"type" : "connection_init" , "payload" : {}})
86+
8287 request_body = self .__request_body (
8388 query = query , variables = variables , operation_name = operation_name
8489 )
@@ -89,7 +94,11 @@ async def subscribe(
8994 async with websockets .connect (
9095 self .endpoint , subprotocols = ["graphql-ws" ]
9196 ) as websocket :
97+ await websocket .send (connection_init_message )
9298 await websocket .send (request_message )
9399 async for response_message in websocket :
94100 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