I'm trying to use the Translator feature as described here: https://tinkerpop.apache.org/docs/3.4.11/reference/#translators
But I get an error: "Cannot read property 'length' of undefined"
I traced it back to this line in the Gremlin source: https://github.com/apache/tinkerpop/blob/b84c3ece2a584f6634f1586f4b84c4e1c349595d/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/translator.js#L53
It looks like instructions
is coming back undefined.
Here is the code I'm testing with:
const traversal = g.V().hasLabel("user").limit(1);
const translator = new gremlin.process.Translator("g");
console.log(translator.translate(traversal));
This is happening with "gremlin": "3.5.0"
. Is this a bug or am I using this feature incorrectly?
You are doing what the documentation says and I think that's the desired way the Translator
should be used but the translate()
function actually requires a Bytecode
object therefore proper usage should be:
const traversal = g.V().hasLabel("user").limit(1);
const translator = new gremlin.process.Translator("g");
console.log(translator.translate(traversal.getBytecode()));
So, the documentation is wrong in the sense that it really shows the desired API rather than the actual API. For now, you will need to call it as shown above, but I've already pushed a fix for the next release that will allow it to be called as shown in the documentation.