Apache TinkerPop
Apache TinkerPop

questions

Root Question Message

gdotv
gdotv1/26/2023
How to connect to a specific graph on Gremlin Server?

Provided a Gremlin server configured with multiple graphs in the graph property of the gremlin server configuration as below:
host: localhost
port: 8182
evaluationTimeout: 30000
channelizer: org.apache.tinkerpop.gremlin.server.channel.WebSocketChannelizer
graphs: {
  graph: conf/tinkergraph-empty.properties, otherGraph: conf/tinkergraph-empty.properties}
...etc


How to specify which graph to connect to in Java (either using RemoteDriverConnection or Client)? I'd assumed DriverRemoteConnection.using(cluster, traversalSourceName) was the place to do this, but that clearly not it!
I'm noticing the Client class allows specifying an alias but that doesn't seem to work either.
What's the proper way of configuring multiple graphs on a server and then connecting to them in Java?
Florian Hockmann
Florian Hockmann1/27/2023
What's important to understand is that the graph name is not the same as the graph traversal source. A graph traversal source needs to be defined on the server for a specific graph. Then you can use the DriverRemoteConnection like you showed.

The traversal source can be bound for example with a Groovy script that is executed on startup. That's typically how it's done for a low number of graphs that are statically defined in the Gremlin Server YAML file. Here is an example for the default case with just one graph: https://github.com/apache/tinkerpop/blob/83d6017be6c62b7350a2d511372b6b8a92e04c64/gremlin-server/scripts/empty-sample.groovy#L45

Graph providers can of course offer different ways to define graphs and create a graph traversal source for them. JanusGraph for example has dynamic graphs and it will create a graph traversal source automatically for each dynamic graph where the graph traversal source is just named <graph.graphname>_traversal: https://docs.janusgraph.org/operations/dynamic-graphs/#dynamic-graph-and-traversal-bindings
gdotv
gdotv1/27/2023
hi Florian, this is great, thanks for explaining all this. I'd assumed this was standard behaviour across the board based on the multi graph functionality I'd seen on DataStax Enterprise Graph, but this now makes a lot more sense. I think I'm going to just go ahead and add that straight to the documentation in G.V().
I've got one more follow up question. In Gremlin/JG, is there a way to automatically discover available graphs via a groovy script? The equivalent command im thinking of for DataStax Graph is system.graphs().
If there's such a feature I can wire that up straight into G.V()'s automatic connection detection and offer users the choice of which graph to connect to
Florian Hockmann
Florian Hockmann1/27/2023
I don't think there is a TinkerPop API for this that would work for all providers.
JanusGraph has something similar as DataStax: ConfiguredGraphFactory.getGraphNames()
https://docs.janusgraph.org/operations/configured-graph-factory/#accessing-the-graphs

This however needs to be sent as a Groovy script to the server. It will probably be improved in the future when we have a complete gRPC API
gdotv
gdotv1/27/2023
awesome, sending scripts won't be an issue for G.V(). got some coding to do now! ill mark this as resolved, i think this covers everything. Thanks a ton
gdotv
gdotv1/27/2023
def variables = []
this.binding.variables.each {k,v -> if(v instanceof GraphTraversalSource) { variables.add(k) }}
return variables
gdotv
gdotv1/27/2023
if you're curious to know how to auto find graphs in gremlin 😄
Florian Hockmann
Florian Hockmann1/27/2023
I think you're better off with JanusGraphFactory.getGraphNames() as ConfiguredGraphFactory.getGraphNames() only works if the ConfiguredGraphFactory is used in the first place which most users probably don't do. JanusGraphFactory.getGraphNames() should always work. Only downside I see is that it includes the management graph for ConfiguredGraphFactory: ConfigurationManagementGraph. Not sure if you want to make that available
gdotv
gdotv1/27/2023
i can probably exclude the management graph
Florian Hockmann
Florian Hockmann1/27/2023
Interesting solution 😄
gdotv
gdotv1/27/2023
for JG G.V() will use the native implementation
gdotv
gdotv1/27/2023
for Gremlin ill have to go with my little hack over there
gdotv
gdotv1/27/2023
it'll definitely do the trick, this is gonna be a cool feature to implement in G.V()
gdotv
gdotv1/27/2023
i highly doubt any other gremlin tool out there can auto detect available graphs
gdotv
gdotv1/27/2023
actually got another question there, trying to figure out something. It seems there's a distinction between @1034102077615521813 's usecase of dynamically generated graph being automatically added per the documentation you supplied and that of having multiple graphs specified in gremlin-server.yaml
gdotv
gdotv1/27/2023
seems in the latter the way to expose them is to ensure the server's start script exposes a traversal for each available graph, and that can then be fed to DriverRemoteConnection or Client to select which traversal to alias to g
gdotv
gdotv1/27/2023
i guess what im wondering here is what if the user hasn't created that graphtraversalsource in the start script? Does it just mean the graphtraversalsource to that graph can't be made global and aliasable to g?
lonniev
lonniev1/29/2023
Sounds promising. Yes, we do what @846643662556495912 states, we have a Gremlin Server startup script which uses the ConfiguredGraphFactory to look up the application's graph and which creates it if not yet present. Following this "find or create" phase, it sets "g" to the traversal source of that graph. Let me know if you code a way for GdotV to perform the get-graph-by-name trick.
Florian Hockmann
Florian Hockmann1/30/2023
i guess what im wondering here is what if the user hasn't created that graphtraversalsource in the start script? Does it just mean the graphtraversalsource to that graph can't be made global and aliasable to g?
Yes, that should be the case. Users really need to expose a graph traversal source to make their graph accessible via Gremlin Server
Florian Hockmann
Florian Hockmann1/30/2023
we have a Gremlin Server startup script which uses the ConfiguredGraphFactory to look up the application's graph and which creates it if not yet present.
I think that shouldn't be necessary as ConfiguredGraphFactory should already create a graph traversal source automatically for every created graph with then name <graph.graphname>_traversal. But you can of course still do it like that if you want to
gdotv
gdotv1/30/2023
thanks for letting me know, in this case I'm happy to consider this "user's fault" type situation if they create a graph on the server but don't expose its graphtraversalsource as a global variable, at least that seems reasonable to me
gdotv
gdotv2/1/2023
@765668250331381840 not sure if i did this right with this question btw, i couldn't figure out how to mark it as resolved so i just added the tag manually but im not convinced that'll then put it up on stackoverflow, am i missing something there?
spmallette
spmallette2/1/2023
as OP you should have had rights to mark it resolved
spmallette
spmallette2/1/2023
hit the ellipse button on the answer that is the right one then Apps > Mark Solution
spmallette
spmallette2/1/2023
do you see that @206896151968874506
spmallette
spmallette2/1/2023
i cleared the tag so that you could give it a try
gdotv
gdotv2/1/2023
weird, it says i can close the post but no actual way to mark solution
gdotv
gdotv2/1/2023
spmallette
spmallette2/1/2023
i think you're clicking on the question
spmallette
spmallette2/1/2023
click on the ellipse of florian's answer you want to mark the solution
gdotv
gdotv2/1/2023
ah, yup, silly me
gdotv
gdotv2/1/2023
thanks
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy