From d75a90e497a16d344f8617352d010fb2fd05c5b7 Mon Sep 17 00:00:00 2001 From: Christophe Willemsen Date: Thu, 28 Oct 2021 17:44:17 +0200 Subject: [PATCH 1/7] failing test for relationship directive --- .../kotlin/org/neo4j/graphql/CypherTests.kt | 3 + .../resources/relationship-directive.adoc | 72 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 core/src/test/resources/relationship-directive.adoc diff --git a/core/src/test/kotlin/org/neo4j/graphql/CypherTests.kt b/core/src/test/kotlin/org/neo4j/graphql/CypherTests.kt index 39e33391..ca7375b8 100644 --- a/core/src/test/kotlin/org/neo4j/graphql/CypherTests.kt +++ b/core/src/test/kotlin/org/neo4j/graphql/CypherTests.kt @@ -71,6 +71,9 @@ class CypherTests { @TestFactory fun `custom-fields`() = CypherTestSuite("custom-fields.adoc", neo4j).generateTests() + @TestFactory + fun `relationship-directive`() = CypherTestSuite("relationship-directive.adoc", neo4j).generateTests() + @TestFactory fun `test issues`() = createTestsInPath("issues", { CypherTestSuite(it, neo4j).generateTests() }) diff --git a/core/src/test/resources/relationship-directive.adoc b/core/src/test/resources/relationship-directive.adoc new file mode 100644 index 00000000..5d1ba045 --- /dev/null +++ b/core/src/test/resources/relationship-directive.adoc @@ -0,0 +1,72 @@ +:toc: + += Cypher Directive Test + +== Schema + +[source,graphql,schema=true] +---- +type Role @relation(name:"ACTED_IN", from:"actor", to:"movie") { + actor: Person + movie: Movie + roles: [String] + type: String @cypher(statement:""" + RETURN type(this) + """) +} + +type Person { + name: String + born: Int + roles: [Role] + _all: String + _id: ID! +} + +type Movie { + title: String + released: Int + characters: [Role] + _all: String + _id: ID! + _labels: [String] @cypher(statement:""" + RETURN labels(this) + """) +} + +---- + +== Queries + +=== Simple Cypher Directive on Field + +.GraphQL-Query +[source,graphql] +---- +query { + person(first: 1) { + roles { + type + } + } +} +---- + +.Cypher Params +[source,json] +---- +{} +---- + +.Cypher +[source,cypher] +---- +MATCH (person:Person) +RETURN person { + roles: [(person)-[personRoles:ACTED_IN]->(personRolesMovie:Movie) | personRoles { + type: apoc.cypher.runFirstColumnSingle('WITH $this AS this RETURN type(this)', { + this: personRoles + }) + }] +} AS person LIMIT $personFirst +---- From da6613ef667cb587682a27878c25fdad24f722f3 Mon Sep 17 00:00:00 2001 From: Christophe Willemsen Date: Thu, 28 Oct 2021 17:56:00 +0200 Subject: [PATCH 2/7] fix relationship directive using wrong alias --- .../org/neo4j/graphql/handler/projection/ProjectionBase.kt | 2 +- core/src/test/resources/relationship-directive.adoc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt b/core/src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt index d6be430a..43b566b5 100644 --- a/core/src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt +++ b/core/src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt @@ -261,7 +261,7 @@ open class ProjectionBase( val cypherDirective = fieldDefinition.cypherDirective() val isObjectField = fieldDefinition.type.inner() is GraphQLFieldsContainer if (cypherDirective != null) { - val query = cypherDirective(field.contextualize(variable), fieldDefinition, field, cypherDirective, propertyContainer.requiredSymbolicName) + val query = cypherDirective(field.contextualize(variable), fieldDefinition, field, cypherDirective, variable.concat("")) projections += if (isObjectField && !cypherDirective.passThrough) { projectListComprehension(variable, field, fieldDefinition, env, query, variableSuffix) } else { diff --git a/core/src/test/resources/relationship-directive.adoc b/core/src/test/resources/relationship-directive.adoc index 5d1ba045..52ae8d11 100644 --- a/core/src/test/resources/relationship-directive.adoc +++ b/core/src/test/resources/relationship-directive.adoc @@ -44,7 +44,7 @@ type Movie { [source,graphql] ---- query { - person(first: 1) { + person { roles { type } @@ -68,5 +68,5 @@ RETURN person { this: personRoles }) }] -} AS person LIMIT $personFirst +} AS person ---- From cafd85407e328e3b6c294197359dc092a0d2f83a Mon Sep 17 00:00:00 2001 From: Christophe Willemsen Date: Thu, 28 Oct 2021 18:24:36 +0200 Subject: [PATCH 3/7] moved test to issues tests --- core/src/test/kotlin/org/neo4j/graphql/CypherTests.kt | 3 --- .../{relationship-directive.adoc => issues/gh-245.adoc} | 0 2 files changed, 3 deletions(-) rename core/src/test/resources/{relationship-directive.adoc => issues/gh-245.adoc} (100%) diff --git a/core/src/test/kotlin/org/neo4j/graphql/CypherTests.kt b/core/src/test/kotlin/org/neo4j/graphql/CypherTests.kt index ca7375b8..39e33391 100644 --- a/core/src/test/kotlin/org/neo4j/graphql/CypherTests.kt +++ b/core/src/test/kotlin/org/neo4j/graphql/CypherTests.kt @@ -71,9 +71,6 @@ class CypherTests { @TestFactory fun `custom-fields`() = CypherTestSuite("custom-fields.adoc", neo4j).generateTests() - @TestFactory - fun `relationship-directive`() = CypherTestSuite("relationship-directive.adoc", neo4j).generateTests() - @TestFactory fun `test issues`() = createTestsInPath("issues", { CypherTestSuite(it, neo4j).generateTests() }) diff --git a/core/src/test/resources/relationship-directive.adoc b/core/src/test/resources/issues/gh-245.adoc similarity index 100% rename from core/src/test/resources/relationship-directive.adoc rename to core/src/test/resources/issues/gh-245.adoc From 51adecbf93e43bb15159ca794881a121ef01d7a2 Mon Sep 17 00:00:00 2001 From: Christophe Willemsen Date: Thu, 28 Oct 2021 18:26:07 +0200 Subject: [PATCH 4/7] simplified schema --- core/src/test/resources/issues/gh-245.adoc | 8 -------- 1 file changed, 8 deletions(-) diff --git a/core/src/test/resources/issues/gh-245.adoc b/core/src/test/resources/issues/gh-245.adoc index 52ae8d11..a91729d3 100644 --- a/core/src/test/resources/issues/gh-245.adoc +++ b/core/src/test/resources/issues/gh-245.adoc @@ -9,7 +9,6 @@ type Role @relation(name:"ACTED_IN", from:"actor", to:"movie") { actor: Person movie: Movie - roles: [String] type: String @cypher(statement:""" RETURN type(this) """) @@ -19,19 +18,12 @@ type Person { name: String born: Int roles: [Role] - _all: String - _id: ID! } type Movie { title: String released: Int characters: [Role] - _all: String - _id: ID! - _labels: [String] @cypher(statement:""" - RETURN labels(this) - """) } ---- From cf75d5af48f2fd4f7c05a41e815b8f7d33a4cefa Mon Sep 17 00:00:00 2001 From: Christophe Willemsen Date: Thu, 28 Oct 2021 18:26:49 +0200 Subject: [PATCH 5/7] remove concat() usage --- .../org/neo4j/graphql/handler/projection/ProjectionBase.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt b/core/src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt index 43b566b5..f8e480d5 100644 --- a/core/src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt +++ b/core/src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt @@ -261,7 +261,7 @@ open class ProjectionBase( val cypherDirective = fieldDefinition.cypherDirective() val isObjectField = fieldDefinition.type.inner() is GraphQLFieldsContainer if (cypherDirective != null) { - val query = cypherDirective(field.contextualize(variable), fieldDefinition, field, cypherDirective, variable.concat("")) + val query = cypherDirective(field.contextualize(variable), fieldDefinition, field, cypherDirective, variable) projections += if (isObjectField && !cypherDirective.passThrough) { projectListComprehension(variable, field, fieldDefinition, env, query, variableSuffix) } else { From 74f07d9146ce74c70d66d71f21aa29e78ed3c552 Mon Sep 17 00:00:00 2001 From: Christophe Willemsen Date: Thu, 28 Oct 2021 18:35:31 +0200 Subject: [PATCH 6/7] add description to test --- core/src/test/resources/issues/gh-245.adoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/test/resources/issues/gh-245.adoc b/core/src/test/resources/issues/gh-245.adoc index a91729d3..4084af27 100644 --- a/core/src/test/resources/issues/gh-245.adoc +++ b/core/src/test/resources/issues/gh-245.adoc @@ -1,6 +1,7 @@ :toc: +:description: Asserts cypher directives can be used on rich relationships and the relationship itself can be used in the cypher query -= Cypher Directive Test += Cypher Directive Computing Relationship Type To Field Test == Schema From 820357081cd9df809a1c820d02eb9aeea8f545d7 Mon Sep 17 00:00:00 2001 From: Christophe Willemsen Date: Thu, 28 Oct 2021 18:40:07 +0200 Subject: [PATCH 7/7] renamed test file --- ...{gh-245.adoc => gh-245-cypher-directive-on-relationship.adoc} | 1 - 1 file changed, 1 deletion(-) rename core/src/test/resources/issues/{gh-245.adoc => gh-245-cypher-directive-on-relationship.adoc} (86%) diff --git a/core/src/test/resources/issues/gh-245.adoc b/core/src/test/resources/issues/gh-245-cypher-directive-on-relationship.adoc similarity index 86% rename from core/src/test/resources/issues/gh-245.adoc rename to core/src/test/resources/issues/gh-245-cypher-directive-on-relationship.adoc index 4084af27..4ea8344a 100644 --- a/core/src/test/resources/issues/gh-245.adoc +++ b/core/src/test/resources/issues/gh-245-cypher-directive-on-relationship.adoc @@ -1,5 +1,4 @@ :toc: -:description: Asserts cypher directives can be used on rich relationships and the relationship itself can be used in the cypher query = Cypher Directive Computing Relationship Type To Field Test