diff --git a/readme.adoc b/readme.adoc index cb17cc54..2502d189 100644 --- a/readme.adoc +++ b/readme.adoc @@ -202,14 +202,14 @@ curl -XPOST http://localhost:4567/graphql -d'{"query":"{person {name}}"}' * aliases * inline and named fragments * auto-generate queries +* @cypher for fields +* auto-generate mutations === Next -* auto-generate mutations * sorting (nested) * interfaces * input types -* @cypher for fields * unions * scalars * date(time), spatial diff --git a/src/test/kotlin/org/neo4j/graphql/MovieSchemaTest.kt b/src/test/kotlin/org/neo4j/graphql/MovieSchemaTest.kt index 38e8be9b..8cba7b85 100644 --- a/src/test/kotlin/org/neo4j/graphql/MovieSchemaTest.kt +++ b/src/test/kotlin/org/neo4j/graphql/MovieSchemaTest.kt @@ -28,33 +28,11 @@ class MovieSchemaTest { )) } -/* -@Test fun `testsimple Cypher query`() { val graphQLQuery = """{ Movie(title: "River Runs Through It, A") { title } }""", expectedCypherQuery = """MATCH (movie:Movie {title:${"$"}title}) RETURN movie { .title } AS movie SKIP ${"$"}offset"""; - - testTranslation(graphQLQuery, expectedCypherQuery, mapOf( - "title" to "River Runs Through It, A", - "first" to -1, - "offset" to 0 - )) -} - -fun `testSimple skip limit`() { - val graphQLQuery = """{ - Movie("title" to "River Runs Through It, A", first: 1, offset: 0) { - title - year - } -} - """val expectedCypherQuery = - """MATCH (movie:Movie {title:${"$"}title}) RETURN movie { .title , .year } AS movie SKIP ${"$"}offset LIMIT ${"$"}first"""; - - testTranslation(graphQLQuery, expectedCypherQuery, mapOf( - "title" to "River Runs Through It, A", - first: 1, - "offset" to 0 - )) -} + @Test fun testTck() { + TckTest(schema).testTck("movie-test.md",0, false) + } +/* fun `testCypher projection skip limit`() { val graphQLQuery = """{ Movie(title: "River Runs Through It, A") { diff --git a/src/test/kotlin/org/neo4j/graphql/TckTest.kt b/src/test/kotlin/org/neo4j/graphql/TckTest.kt index 9224f8b6..130f5273 100644 --- a/src/test/kotlin/org/neo4j/graphql/TckTest.kt +++ b/src/test/kotlin/org/neo4j/graphql/TckTest.kt @@ -40,24 +40,25 @@ class TckTest(val schema:String) { return testData } - public fun testTck(fileName: String, expectedFailures: Int) { + public fun testTck(fileName: String, expectedFailures: Int, fail:Boolean = false) { val pairs = loadQueryPairsFrom(fileName) val failed = pairs.map { try { assertQuery(schema, it.first, it.second, it.third); null } catch (ae: Throwable) { - ae.message + if (fail) throw ae else ae.message } } .filterNotNull() failed.forEach(::println) + println("""Succeeded in "$fileName": ${pairs.size - failed.size} of ${pairs.size}""") Assert.assertEquals("${failed.size} failed of ${pairs.size}", expectedFailures, failed.size) } companion object { fun assertQuery(schema:String, query: String, expected: String, params : Map = emptyMap()) { val result = Translator(SchemaBuilder.buildSchema(schema)).translate(query).first() - Assert.assertEquals(expected, result.query) + Assert.assertEquals(expected.replace(Regex("\\s+")," "), result.query) Assert.assertTrue("${params} IN ${result.params}", result.params.entries.containsAll(params.entries)) } } diff --git a/src/test/resources/movie-test.md b/src/test/resources/movie-test.md new file mode 100644 index 00000000..49018d81 --- /dev/null +++ b/src/test/resources/movie-test.md @@ -0,0 +1,89 @@ +## Filter Test TCK + + +### Schema +```schema + +``` + +### Basic Test + +```graphql +{ Movie(title: "River Runs Through It, A") { title } } +``` +```params +{"movieTitle":"River Runs Through It, A"} +``` +```cypher +MATCH (movie:Movie) +WHERE movie.title = $movieTitle +RETURN movie { .title } AS movie +``` + +### Testing Paging + +```graphql +{ + Movie("title" to "River Runs Through It, A", first: 1, offset: 0) { + title + year + } +} +``` + +```params +{"movieTitle": "River Runs Through It, A", "first": 1, "offset": 0} +``` + +```cypher +MATCH (movie:Movie) +WHERE movie.title = $movieTitle +RETURN movie { .title , .year } AS movie +SKIP $offset LIMIT $first +``` + +### Testing Projection + +```graphql +{ + Movie(title: "River Runs Through It, A") { + title + actors { + name + } + } + } +``` + +```params +{"movieTitle": "River Runs Through It, A"} +``` + +```cypher +MATCH (movie:Movie) +WHERE movie.title = $movieTitle +RETURN movie { .title,actors:[(movie)<-[:ACTED_IN]-(movieActors:Actor) | movieActors { .name }] } AS movie +``` + +### Testing Projection with sub-paging + +```graphql +{ + Movie(title: "River Runs Through It, A") { + title + actors(first:3) { + name + } + } + } +``` +#### todo ,"actorsFirst":3 +```params +{"movieTitle": "River Runs Through It, A"} +``` + +```cypher +MATCH (movie:Movie) +WHERE movie.title = $movieTitle +RETURN movie { .title,actors:[(movie)<-[:ACTED_IN]-(movieActors:Actor) | movieActors { .name }][0..3] } AS movie +```