Skip to content

Commit 4ef4093

Browse files
feat(Slash gRPC Client): Add gRPC support for Slash endpoints
2 parents 652d4f7 + 5a29202 commit 4ef4093

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

pydgraph/client_stub.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from pydgraph.meta import VERSION
2020
from pydgraph.proto import api_pb2_grpc as api_grpc
2121

22+
from urllib.parse import urlparse
23+
2224
__author__ = 'Garvit Pahal <[email protected]>'
2325
__maintainer__ = 'Martin Martinez Rivera <[email protected]>'
2426
__version__ = VERSION
@@ -50,7 +52,6 @@ def async_alter(self, operation, timeout=None, metadata=None, credentials=None):
5052
return self.stub.Alter.future(operation, timeout=timeout, metadata=metadata,
5153
credentials=credentials)
5254

53-
5455
def query(self, req, timeout=None, metadata=None, credentials=None):
5556
"""Runs query or mutate operation."""
5657
return self.stub.Query(req, timeout=timeout, metadata=metadata,
@@ -82,3 +83,18 @@ def close(self):
8283
pass
8384
del self.channel
8485
del self.stub
86+
87+
@staticmethod
88+
def from_slash_endpoint(slash_end_point, api_key):
89+
"""Returns Dgraph Client stub for the Slash GraphQL endpoint"""
90+
url = urlparse(slash_end_point)
91+
url_parts = url.netloc.split(".", 1)
92+
host = url_parts[0] + ".grpc." + url_parts[1]
93+
creds = grpc.ssl_channel_credentials()
94+
call_credentials = grpc.metadata_call_credentials(
95+
lambda context, callback: callback((("authorization", api_key),), None))
96+
composite_credentials = grpc.composite_channel_credentials(
97+
creds, call_credentials)
98+
client_stub = DgraphClientStub('{host}:{port}'.format(
99+
host=host, port="443"), composite_credentials, options=(('grpc.enable_http_proxy', 0),))
100+
return client_stub

0 commit comments

Comments
 (0)