11= JVM Library to translate GraphQL queries and mutations to Neo4j's Cypher
2+ :version: 1.0.0
23
34This is a beta GraphQL transpiler written in Kotlin.
45
@@ -38,7 +39,7 @@ Thanks a lot to the maintainers of `graphql-java` for the awesome library.
3839
3940== Usage
4041
41- You can use the library as dependency: `org.neo4j:neo4j-graphql-java:1.0.0-M02 ` in any JVM program.
42+ You can use the library as dependency: `org.neo4j:neo4j-graphql-java:{version} ` in any JVM program.
4243
4344The basic usage should be:
4445
@@ -59,7 +60,10 @@ val schema =
5960val query = """ { p:personByName(name:"Joe") { age } } """
6061
6162val schema = SchemaBuilder.buildSchema(idl)
62- val (cypher, params) = Translator(schema).translate(query, params)
63+ val ctx = QueryContext()
64+ // SETUP otimizer strategy
65+ // ctx.optimizedQuery = setOf(QueryContext.OptimizationStrategy.FILTER_AS_MATCH)
66+ val (cypher, params) = Translator(schema).translate(query, params, ctx)
6367
6468// generated Cypher
6569cypher == "MATCH (p:Person) WHERE p.name = $pName RETURN p {.age} as p"
@@ -74,6 +78,7 @@ You find more usage examples in the:
7478* link:src/test/resources/translator-tests1.adoc[Translator 1 TCK]
7579* link:src/test/resources/translator-tests2.adoc[Translator 2 TCK]
7680* link:src/test/resources/translator-tests3.adoc[Translator 3 TCK]
81+ * link:src/test/resources/optimized-query-for-filter.adoc[Alternative Filter TCK]
7782
7883== Demo
7984
@@ -86,13 +91,13 @@ In case you wand to bind the neo4j driver directly to the graphql schema you can
8691link:src/test/kotlin/DataFetcherInterceptorDemo.kt[use the DataFetchingInterceptor to
8792intercept the cypher queries].
8893
89- [source,groovy]
94+ [source,groovy,subs=attributes ]
9095----
9196// Simplistic GraphQL Server using SparkJava
9297@Grapes([
9398 @Grab('com.sparkjava:spark-core:2.7.2'),
9499 @Grab('org.neo4j.driver:neo4j-java-driver:1.7.2'),
95- @Grab('org.neo4j:neo4j-graphql-java:1.0.0-M01 '),
100+ @Grab('org.neo4j:neo4j-graphql-java:{version} '),
96101 @Grab('com.google.code.gson:gson:2.8.5')
97102])
98103
@@ -518,6 +523,27 @@ You can also apply nested filter on relations, which use suffixes like `("",not,
518523
519524NOTE: Those nested input types are not yet generated, we use leniency in the parser.
520525
526+ ==== Optimized Filters
527+
528+ If you encounter performance problems with the cypher queries generated for the filter,
529+ you can activate an alternative algorithm using:
530+
531+ [source,kotlin]
532+ ----
533+ var query
534+ try {
535+ val ctx = QueryContext(optimizedQuery = setOf(QueryContext.OptimizationStrategy.FILTER_AS_MATCH))
536+ query = translator.translate(query, params, ctx)
537+ } catch (e: OptimizedQueryException) {
538+ query = translator.translate(query, params)
539+ }
540+ ----
541+
542+ If no query can be generated by the alternative algorithm, an `OptimizedQueryException` is thrown,
543+ so that a fallback to the actual algorithm can used.
544+
545+ link:src/test/resources/optimized-query-for-filter.adoc[Examples of the alternative algorithm] can be seen in the tests.
546+
521547=== Inline and Named Fragments
522548
523549We support inline and named fragments according to the GraphQL spec.
0 commit comments