我为这样一个基本的问题道歉,但我似乎不知道如何做,文档都很具体。
我只是想用gremlin连接到一个标准的Gremlin DB(Cosmos)。它在服务器上工作得很好,但是当我从浏览器连接时,我得到了这个错误。
Error: ws does not work in the browser. Browser clients must use the native WebSocket object
没有什么非常复杂的东西,而且错误似乎也很清楚。
下面是代码。
constructor() {
var authenticator = new Gremlin.driver.auth.PlainTextSaslAuthenticator(`/dbs/${config.database}/colls/${config.collection}`, config.primaryKey);
this.gremlin_config_options = {
authenticator,
traversalsource: "g",
rejectUnauthorized: true,
mimeType: "application/vnd.gremlin-v2.0+json"
}
var DriverRemoteConnection = Gremlin.driver.DriverRemoteConnection;
this.Graph = Gremlin.structure.Graph;
var dc = new DriverRemoteConnection(this.gremlin_websocket,this.gremlin_config_options);
this.graph = new this.Graph();
this.g = this.graph.traversal().withRemote(this.gremlin_websocket);
};
当我执行下面的代码时,它没有出现Javascript错误。
constructor() {
var authenticator = new Gremlin.driver.auth.PlainTextSaslAuthenticator(`/dbs/${config.database}/colls/${config.collection}`, config.primaryKey);
this.gremlin_config_options = {
authenticator,
traversalsource: "g",
rejectUnauthorized: true,
mimeType: "application/vnd.gremlin-v2.0+json"
}
this.Graph = Gremlin.structure.Graph;
this.gremlin_websocket = new WebSocket('ws://test_db.gremlin.cosmos.azure.com:8182/')
this.graph = new this.Graph();
this.g = this.graph.traversal().withRemote(this.gremlin_websocket);
};
然而,我需要传递验证和收集信息(目前在authenticator对象中)。但WebSocket似乎不支持它,而Driver Remote Connection似乎也不原生地采取Websocket。我应该怎么做呢?
不幸的是,我不认为 gremlin-javascript 在浏览器中工作得很好。我想这就是你所遇到的问题。需要注意的是,已经有一个问题,那就是 TINKERPOP-2143 和一个 相关的拉动请求 现在已经部分完成了很久,但还没有完成。