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:
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?
Solution:Jump to solution
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...17 Replies
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-bindingsGitHub
tinkerpop/empty-sample.groovy at 83d6017be6c62b7350a2d511372b6b8a92...
Apache TinkerPop - a graph computing framework. Contribute to apache/tinkerpop development by creating an account on GitHub.
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
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 APIawesome, 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
if you're curious to know how to auto find graphs in gremlin 😄
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 availablei can probably exclude the management graph
Interesting solution 😄
for JG G.V() will use the native implementation
for Gremlin ill have to go with my little hack over there
it'll definitely do the trick, this is gonna be a cool feature to implement in G.V()
i highly doubt any other gremlin tool out there can auto detect available graphs
actually got another question there, trying to figure out something. It seems there's a distinction between @lonniev '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
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
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?
Sounds promising. Yes, we do what @Florian Hockmann 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.
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
Solution
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 tothanks 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
@spmallette 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?
as OP you should have had rights to mark it resolved
hit the ellipse button on the answer that is the right one then Apps > Mark Solution
do you see that @gdotv
i cleared the tag so that you could give it a try
weird, it says i can close the post but no actual way to mark solution
i think you're clicking on the question
click on the ellipse of florian's answer you want to mark the solution
ah, yup, silly me
thanks