From 8795719c71cae9114ad34db5c40191e7bb17896e Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Wed, 30 Nov 2022 12:52:54 -0600 Subject: [PATCH 1/5] Update graphql_client.py --- python_graphql_client/graphql_client.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python_graphql_client/graphql_client.py b/python_graphql_client/graphql_client.py index 1d3d104..40dd712 100644 --- a/python_graphql_client/graphql_client.py +++ b/python_graphql_client/graphql_client.py @@ -108,5 +108,8 @@ async def subscribe( self.logger.info("the server accepted the connection") elif response_body["type"] == "ka": self.logger.info("the server sent a keep alive message") + elif response_body["type"] == "complete": + await websocket.close() + return else: handle(response_body["payload"]) From 3e4b258a04c900343675657dd0592f098364ae28 Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Wed, 30 Nov 2022 12:56:33 -0600 Subject: [PATCH 2/5] make more concise --- python_graphql_client/graphql_client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python_graphql_client/graphql_client.py b/python_graphql_client/graphql_client.py index 40dd712..d4004e6 100644 --- a/python_graphql_client/graphql_client.py +++ b/python_graphql_client/graphql_client.py @@ -109,7 +109,6 @@ async def subscribe( elif response_body["type"] == "ka": self.logger.info("the server sent a keep alive message") elif response_body["type"] == "complete": - await websocket.close() return else: handle(response_body["payload"]) From 07b575aadc8f6acf94585c73f1e1bbefb324db91 Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Tue, 15 Aug 2023 17:51:16 -0500 Subject: [PATCH 3/5] add session --- python_graphql_client/graphql_client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python_graphql_client/graphql_client.py b/python_graphql_client/graphql_client.py index d4004e6..2f55ec3 100644 --- a/python_graphql_client/graphql_client.py +++ b/python_graphql_client/graphql_client.py @@ -11,12 +11,16 @@ class GraphqlClient: """Class which represents the interface to make graphQL requests through.""" - def __init__(self, endpoint: str, headers: dict = {}, **kwargs: Any): + def __init__(self, endpoint: str, headers: dict = {}, session=None, **kwargs: Any): """Insantiate the client.""" self.logger = logging.getLogger(__name__) self.endpoint = endpoint self.headers = headers self.options = kwargs + self.session = session + if self.session is None: + self.session = requests.Session() + def __request_body( self, query: str, variables: dict = None, operation_name: str = None @@ -44,7 +48,7 @@ def execute( query=query, variables=variables, operation_name=operation_name ) - result = requests.post( + result = self.session.post( self.endpoint, json=request_body, headers={**self.headers, **headers}, From 0c9842c561318034de22e66c812c934ba66d9855 Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Tue, 21 Nov 2023 11:16:36 -0600 Subject: [PATCH 4/5] update protocol --- python_graphql_client/graphql_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python_graphql_client/graphql_client.py b/python_graphql_client/graphql_client.py index 2f55ec3..55776f2 100644 --- a/python_graphql_client/graphql_client.py +++ b/python_graphql_client/graphql_client.py @@ -96,12 +96,12 @@ async def subscribe( query=query, variables=variables, operation_name=operation_name ) request_message = json.dumps( - {"type": "start", "id": "1", "payload": request_body} + {"type": "subscribe", "id": "1", "payload": request_body} ) async with websockets.connect( self.endpoint, - subprotocols=["graphql-ws"], + subprotocols=["graphql-transport-ws"], extra_headers={**self.headers, **headers}, ) as websocket: await websocket.send(connection_init_message) From 635309f961df666f8be09be1b977a827ca935f49 Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Wed, 22 Nov 2023 14:40:08 -0600 Subject: [PATCH 5/5] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index fcd8f1e..011c294 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name="python_graphql_client", - version="0.4.3", + version="0.4.4", description="Python GraphQL Client", long_description=long_description, long_description_content_type="text/markdown",