Thanks for the help Robert; not there yet but making progress.
Taking the gremlin console out of the picture and focusing only on talking to the db via my javascript gremlin client, I have the following unit tests
it("4) can invoke predefined custom predicate", function(done) {
client.execute('addItUp(2,3)',{}, function(err,result) {
assert(result.length)
assert(result[0]==5)
done()
})
}) // succeeds
it("5) can invoke my predefined custom predicate", function(done) {
client.execute('listContains([1,2,3],3)',{}, function(err,result) {
assert(!err)
assert(result.length)
assert(result[0]==true)
done()
})
}) // succeeds
it("6) can use has() with custom predicate", function(done) {
client.execute('g.V().has("name","v1").has("read", test(listContains,"p3"))',{}, function(err,result) {
console.log('6 returned err, result', err, result )
assert(!err)
assert(result)
assert(result.length)
done()
}) // fails with No such property: listContains for class: Script12 (Error 597)
The first two tests indicate that addItUp() and listContains() are in fact visible to the gremlin server at runtime, so my installation of the custom predicate should be at least in the right place and syntactically reasonabl, however the third test fails with the error 'No such property: listContains for class:Script12'.
On a whim I tried rewriting the third test to treat listContains as a built-in predicate,
it("6) can use has() with custom predicate", function(done) {
client.execute('g.V().has("name","v1").has("read", listContains("p3"))',{}, function(err,result) {
console.log('6 returned err, result', err, result )
assert(!err)
assert(result)
assert(result.length)
done()
})
}) // fails with No signature of method: Script1.listContains() is applicable for argument types: (java.lang.String) values.
This is a different error - it indicates that the signature of listContains() doesn't match the provided arguments. If I give it 2 arguments explicitly, ie
it("6) can use has() with custom predicate", function(done) {
client.execute('g.V().has("name","v1").has("read", listContains([1,2,3],1))',{}, function(err,result) {
console.log('6 returned err, result', err, result )
assert(!err)
assert(result)
assert(result.length)
done()
})
}) // fails with empty result (but no error!)
No errors this time - but also no results. It would appear that listContains was invoked, but it should have returned true and the query should have therefore produced a result.
Anyway so the problem would seem to be with either the has step syntax or possibly my function definition?
def listContains(x,y) { x.contains(y) }
My Setup is gremlin server 3.2 talking to Titan 1.0.0
Help appreciated!