I've seen multiple examples of this being done (various languages) which suggests this should work. Perhaps I'm missing a step? Commented out the lines that indicate other things I've tried.
Here's how I'm getting my gremlin client and also a graphTraversalSource to use directly.
var gremlinServer = new GremlinServer(endpoint, 8182, enableSsl: true);
GremlinClient = new GremlinClient(gremlinServer);
//var remoteConnection = new DriverRemoteConnection(GremlinClient, "g");
var remoteConnection = new DriverRemoteConnection(GremlinClient);
//g = AnonymousTraversalSource.Traversal().WithRemote(remoteConnection);
g = new Graph().Traversal().WithRemote(remoteConnection);
If I submit queries as strings like this:
var gndrSetCnt = GremlinQueryCount(GremlinClient, "g.V().count().next();");
var gndrResult = gndrSetCnt.Result;
and then....
private async Task<long> GremlinQueryCount(GremlinClient gremlinClient, string query)
{
return await gremlinClient.SubmitWithSingleResultAsync<long>(query);
}
that works fine, as clumsy as it is. However, if I try to use the "g" directly, like this:
var example = g.V().Count().Next();
then I get an error like this:
Gremlin.Net.Driver.Exceptions.ResponseException: 'InvalidRequestArguments: {"detailedMessage":"A message with [bytecode] op code requires the [aliases] argument to be a Map containing one alias assignment named 'g'.","requestId":"ae024dd7-0fca-472b-acc6-7f717ca4bf2d","code":"InvalidParameterException"}'
Am I missing a step? I've seen this in multiple examples where nothing else seems to have been done, but I confess, only one in C# and that was only partial code, more of a tutorial. No aliases seem to have been injected, g just seems to be available by default? Again note I'm using g in the submitted groovy script, and that works.
For the record as per a suggestion, we added logging and this is what a sample statement produced:
"RequestMessage{, requestId=709ba190-0ce9-4272-aadb-4b28c21accf6, op='bytecode', processor='traversal', args={gremlin={$type=System.Collections.Generic.Dictionary2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib, @type=g:Bytecode, @value={$type=System.Collections.Generic.Dictionary
2[[System.String, mscorlib],[System.Collections.Generic.IEnumerable1[[System.Collections.Generic.IEnumerable
1[[System.Object, mscorlib]], mscorlib]], mscorlib]], mscorlib, step={$type=System.Linq.Enumerable+WhereSelectListIterator2[[Gremlin.Net.Process.Traversal.Instruction, Gremlin.Net],[System.Collections.Generic.IEnumerable
1[[System.Object, mscorlib]], mscorlib]], System.Core, $values=[[V], [hasLabel, article], [has, languageCode, fr-FR], [count]]}}}, aliases={$type=System.Collections.Generic.Dictionary2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib, g=g}, $type=System.Collections.Generic.Dictionary
2[[System.String, mscorlib],[System.Object, mscorlib]], mscorlib}}"
I'm not entirely sure if that's helpful. The original error message is suggesting that somehow the statement isn't starting with "g" but I don't see why it isn't, given what I'm doing - which is building a gts object from a drm which has "g" as the traveral source.