Skip to content

Commit 6abd6b2

Browse files
authored
accept custom grpc options in from_cloud function (#215)
Although the `DgraphClientStub` constructor accepts custom gRPC options for connecting to on-prem/self-hosted Dgraph backends, the same cannot be passed to the `from_cloud` function while connecting to Cloud backends. This PR allows passing of gRPC options like `grpc.max_receive_message_length` to the `from_cloud` function.
1 parent a593cd7 commit 6abd6b2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pydgraph/client_stub.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,18 @@ def parse_host(cloud_endpoint):
105105
# client_stub = pydgraph.DgraphClientStub.from_cloud("cloud_endpoint", "api-key")
106106
# client = pydgraph.DgraphClient(client_stub)
107107
@staticmethod
108-
def from_cloud(cloud_endpoint, api_key):
108+
def from_cloud(cloud_endpoint, api_key, options=None):
109109
"""Returns Dgraph Client stub for the Dgraph Cloud endpoint"""
110110
host = DgraphClientStub.parse_host(cloud_endpoint)
111111
creds = grpc.ssl_channel_credentials()
112112
call_credentials = grpc.metadata_call_credentials(
113113
lambda context, callback: callback((("authorization", api_key),), None))
114114
composite_credentials = grpc.composite_channel_credentials(
115115
creds, call_credentials)
116+
if options==None:
117+
options=[('grpc.enable_http_proxy', 0)]
118+
else:
119+
options.append(('grpc.enable_http_proxy', 0))
116120
client_stub = DgraphClientStub('{host}:{port}'.format(
117-
host=host, port="443"), composite_credentials, options=(('grpc.enable_http_proxy', 0),))
121+
host=host, port="443"), composite_credentials, options=options)
118122
return client_stub

0 commit comments

Comments
 (0)