opencypher / cypher-for-gremlin

Cypher for Gremlin adds Cypher support to any Gremlin graph database.
Apache License 2.0
359 stars 48 forks source link

Feature Request: Create config/sessions with translatorSupplier #347

Open vigorouscoding opened 4 years ago

vigorouscoding commented 4 years ago

I would like to connect to a Neptune database using Cypher for queries (and use multiple labels in queries which requires the TranslatorFeature.MULTIPLE_LABELS).

I do get this to work using the following code:

// cluster setup
// .. this is identical in both cases

// client setup
CypherGremlinClient client = CypherGremlinClient.translating(
        cluster.connect(),
        () -> Translator.builder()
                .gremlinGroovy()
                .inlineParameters()
                .enableMultipleLabels()
                .build(TranslatorFlavor.neptune())
);

However - as soon as I start using sessions and a GremlinServerDriver I can't seem to get it work. I run into an exception:

org.opencypher.gremlin.translation.exception.SyntaxException: Multiple labels are not supported
// cluster setup
// .. this is identical in both cases

// driver setup
Config config = Config.build()
        .withTranslation(TranslatorFlavor.neptune())
        .ignoreIds()
        .toConfig();

GremlinServerDriver driver = GremlinDatabase.driver(cluster, config);

I have tried quite a few ways to get this to work but it seems the referenced code line (which creates the CypherGremlinClient in the GremlinServerDriver.session() method) only allows using a TranslatorFlavor.

https://github.com/opencypher/cypher-for-gremlin/blob/ee77607c7c7e931c71828e5fd787195e7fe6ab27/tinkerpop/cypher-gremlin-neo4j-driver/src/main/java/org/opencypher/gremlin/neo4j/driver/GremlinServerDriver.java#L45

I would kindly ask if you could enable users to create a Config with a Supplier<Translator<String, GroovyPredicate>> translatorSupplier which could then be used upon creating of a session to produce a different translating CypherGremlinClient.

Unless I am mistaken there is no way to create sessions with such a translatorSupplier - if I am wrong I'd kindly ask for a nudge in the right direction. I could also create a PR myself if you'd like.

Thank you!