From 1c9b75a32e15ff9a6888855118c9de3185410d53 Mon Sep 17 00:00:00 2001 From: Aravind Bharatha Date: Tue, 26 Mar 2019 12:06:21 -0400 Subject: [PATCH 1/5] Fixing the Bug where first subscription message is lost by updating _start method(minor change) --- graphql_client/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/graphql_client/__init__.py b/graphql_client/__init__.py index 39fd8b4..2b8dad8 100644 --- a/graphql_client/__init__.py +++ b/graphql_client/__init__.py @@ -45,11 +45,13 @@ def _conn_init(self, headers=None): self._conn.send(json.dumps(payload)) self._conn.recv() + def _start(self, payload): _id = gen_id() frame = {'id': _id, 'type': 'start', 'payload': payload} self._conn.send(json.dumps(frame)) - self._conn.recv() + # commenting this as the spec excepts data after start and subscription misses the first data if data is received here + # res = self._conn.recv() return _id def _stop(self, _id): @@ -61,8 +63,8 @@ def query(self, query, variables=None, headers=None): self._conn_init(headers) payload = {'headers': headers, 'query': query, 'variables': variables} _id = self._start(payload) - self._conn.recv() - res = self._stop(_id) + res = self._conn.recv() + self._stop(_id) #print(dir(self._conn)) return res From e486ccb616fb3286247dce50f14486a784e7444e Mon Sep 17 00:00:00 2001 From: Aravind Bharatha Date: Wed, 27 Mar 2019 11:32:54 -0400 Subject: [PATCH 2/5] Adding requested changes --- graphql_client/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/graphql_client/__init__.py b/graphql_client/__init__.py index 2b8dad8..c3d1761 100644 --- a/graphql_client/__init__.py +++ b/graphql_client/__init__.py @@ -45,13 +45,10 @@ def _conn_init(self, headers=None): self._conn.send(json.dumps(payload)) self._conn.recv() - def _start(self, payload): _id = gen_id() frame = {'id': _id, 'type': 'start', 'payload': payload} self._conn.send(json.dumps(frame)) - # commenting this as the spec excepts data after start and subscription misses the first data if data is received here - # res = self._conn.recv() return _id def _stop(self, _id): From c6678b67a17e9310c2e37d1149278fa5934b96a2 Mon Sep 17 00:00:00 2001 From: Aravind Bharatha Date: Wed, 27 Mar 2019 13:50:24 -0400 Subject: [PATCH 3/5] GraphQL basic http client --- graphql_client/GraphQLHttpClient.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 graphql_client/GraphQLHttpClient.py diff --git a/graphql_client/GraphQLHttpClient.py b/graphql_client/GraphQLHttpClient.py new file mode 100644 index 0000000..2d96df7 --- /dev/null +++ b/graphql_client/GraphQLHttpClient.py @@ -0,0 +1,11 @@ +import requests + +class GraphQLHttpClient: + + def __init__(self, url): + self.http_url = url + + def query(self, query, variables=None, headers=None): + payload = { 'headers': headers, 'query' : query, 'variables': variables } + resp = requests.post(self.http_url, json=payload) + return resp \ No newline at end of file From 45d1a6b6fcd71866e33d725b4dddcd435abe37fd Mon Sep 17 00:00:00 2001 From: Aravind Bharatha Date: Wed, 27 Mar 2019 13:53:22 -0400 Subject: [PATCH 4/5] Revert "Adding requested changes" This reverts commit e486ccb616fb3286247dce50f14486a784e7444e. --- graphql_client/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/graphql_client/__init__.py b/graphql_client/__init__.py index c3d1761..2b8dad8 100644 --- a/graphql_client/__init__.py +++ b/graphql_client/__init__.py @@ -45,10 +45,13 @@ def _conn_init(self, headers=None): self._conn.send(json.dumps(payload)) self._conn.recv() + def _start(self, payload): _id = gen_id() frame = {'id': _id, 'type': 'start', 'payload': payload} self._conn.send(json.dumps(frame)) + # commenting this as the spec excepts data after start and subscription misses the first data if data is received here + # res = self._conn.recv() return _id def _stop(self, _id): From 017fcbefeaf701f68873fa8e3c8d6729aff2f078 Mon Sep 17 00:00:00 2001 From: Aravind Bharatha Date: Wed, 27 Mar 2019 14:05:17 -0400 Subject: [PATCH 5/5] Adding mutation wrapper --- graphql_client/GraphQLHttpClient.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/graphql_client/GraphQLHttpClient.py b/graphql_client/GraphQLHttpClient.py index 2d96df7..c7e2cf2 100644 --- a/graphql_client/GraphQLHttpClient.py +++ b/graphql_client/GraphQLHttpClient.py @@ -8,4 +8,7 @@ def __init__(self, url): def query(self, query, variables=None, headers=None): payload = { 'headers': headers, 'query' : query, 'variables': variables } resp = requests.post(self.http_url, json=payload) - return resp \ No newline at end of file + return resp + + def mutation(self, query, variables=None, headers=None): + return self.query(query, variables, headers) \ No newline at end of file