|
19 | 19 | from pydgraph.meta import VERSION
|
20 | 20 | from pydgraph.proto import api_pb2_grpc as api_grpc
|
21 | 21 |
|
| 22 | +from urllib.parse import urlparse |
| 23 | + |
22 | 24 | __author__ = 'Garvit Pahal <[email protected]>'
|
23 | 25 | __maintainer__ = 'Martin Martinez Rivera <[email protected]>'
|
24 | 26 | __version__ = VERSION
|
@@ -50,7 +52,6 @@ def async_alter(self, operation, timeout=None, metadata=None, credentials=None):
|
50 | 52 | return self.stub.Alter.future(operation, timeout=timeout, metadata=metadata,
|
51 | 53 | credentials=credentials)
|
52 | 54 |
|
53 |
| - |
54 | 55 | def query(self, req, timeout=None, metadata=None, credentials=None):
|
55 | 56 | """Runs query or mutate operation."""
|
56 | 57 | return self.stub.Query(req, timeout=timeout, metadata=metadata,
|
@@ -82,3 +83,18 @@ def close(self):
|
82 | 83 | pass
|
83 | 84 | del self.channel
|
84 | 85 | 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