Skip to content

Commit 18bc38f

Browse files
Support Slash backend connection
1 parent 4f70d1d commit 18bc38f

File tree

9 files changed

+7295
-3
lines changed

9 files changed

+7295
-3
lines changed

examples/simple/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const dgraph = require("dgraph-js");
2-
const grpc = require("grpc");
32

43
// Create a client stub.
54
function newClientStub() {
@@ -87,7 +86,7 @@ async function createData(dgraphClient) {
8786
console.log(
8887
`Created person named "Alice" with uid = ${response
8988
.getUidsMap()
90-
.get("alice")}\n`
89+
.get("alice")}\n`,
9190
);
9291

9392
console.log("All created nodes (map from blank node names to uids):");

lib/clientStubFromSlash.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { DgraphClientStub } from "./clientStub";
2+
export declare function clientStubFromSlashGraphQLEndpoint(graphqlEndpoint: string, apiKey: string): DgraphClientStub;

lib/clientStubFromSlash.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.clientStubFromSlashGraphQLEndpoint = void 0;
4+
var grpc = require("@grpc/grpc-js");
5+
var clientStub_1 = require("./clientStub");
6+
var Url = require("url-parse");
7+
var PORT = "443";
8+
function clientStubFromSlashGraphQLEndpoint(graphqlEndpoint, apiKey) {
9+
var url = new Url(graphqlEndpoint);
10+
var urlParts = url.host.split(".");
11+
var firstHalf = urlParts[0];
12+
var secondHalf = urlParts.splice(1).join(".") + ":" + PORT;
13+
var backenedURL = firstHalf + ".grpc." + secondHalf;
14+
console.log(backenedURL);
15+
var metaCreds = grpc.credentials.createFromMetadataGenerator(function (_, callback) {
16+
var metadata = new grpc.Metadata();
17+
metadata.add("authorization", apiKey);
18+
callback(null, metadata);
19+
});
20+
var credentials = grpc.credentials.combineChannelCredentials(grpc.credentials.createSsl(), metaCreds);
21+
return new clientStub_1.DgraphClientStub(backenedURL, credentials);
22+
}
23+
exports.clientStubFromSlashGraphQLEndpoint = clientStubFromSlashGraphQLEndpoint;

lib/dgraph.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * from "./types";
22
export { Operation, Request, TxnContext, Check, Version, NQuad, Value, Facet, Latency, } from "../generated/api_pb";
33
export * from "./clientStub";
44
export * from "./client";
5+
export * from "./clientStubFromSlash";
56
export * from "./txn";
67
export * from "./errors";
78
export * as grpc from "@grpc/grpc-js";

lib/dgraph.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "Facet", { enumerable: true, get: function () { r
2323
Object.defineProperty(exports, "Latency", { enumerable: true, get: function () { return api_pb_1.Latency; } });
2424
__exportStar(require("./clientStub"), exports);
2525
__exportStar(require("./client"), exports);
26+
__exportStar(require("./clientStubFromSlash"), exports);
2627
__exportStar(require("./txn"), exports);
2728
__exportStar(require("./errors"), exports);
2829
exports.grpc = require("@grpc/grpc-js");

0 commit comments

Comments
 (0)