Skip to content

Commit 8af7dad

Browse files
committed
wrap filter in match stage for Mongo,
add test cases
1 parent b768bc2 commit 8af7dad

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

server/connectors/api-connector-mongo/src/main/scala/com/prisma/api/connector/mongo/database/AggregationQueryBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ trait AggregationQueryBuilder extends FilterConditionBuilder with ProjectionBuil
5858
//-------------------------------- Match on Cursor Condition ----------------------------------------
5959
val pipeline = rowValueOpt match {
6060
case None => common
61-
case Some(rowValue) => CursorConditionBuilder.buildCursorCondition(model, queryArguments, rowValue) +: common
61+
case Some(rowValue) => `match`(CursorConditionBuilder.buildCursorCondition(model, queryArguments, rowValue)) +: common
6262
}
6363

6464
database.getCollection(model.dbName).aggregate(pipeline).toFuture.map(_.map(readsId))

server/servers/api/src/test/scala/com/prisma/api/queries/MultiItemConnectionQuerySpec.scala

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.prisma.api.queries
22

3+
import com.prisma.{IgnoreMongo, IgnoreMySql, IgnorePostgres, IgnoreSQLite}
34
import com.prisma.api.ApiSpecBase
45
import com.prisma.shared.schema_dsl.SchemaDsl
56
import org.scalatest.{FlatSpec, Matchers}
67

78
class MultiItemConnectionQuerySpec extends FlatSpec with Matchers with ApiSpecBase {
9+
810
val project = SchemaDsl.fromStringV11() {
911
"""type Todo {
1012
| id: ID! @id
@@ -108,4 +110,83 @@ class MultiItemConnectionQuerySpec extends FlatSpec with Matchers with ApiSpecBa
108110
)
109111
.toString should equal("""{"data":{"todoesConnection":{"edges":[{"node":{"title":"Hello World!"}}]}}}""")
110112
}
113+
114+
"the connection query" should "work when using cursors on Mongo" taggedAs (IgnoreMySql, IgnorePostgres, IgnoreSQLite) in {
115+
116+
val project2 = SchemaDsl.fromStringV11() {
117+
"""type User {
118+
| id: ID! @id
119+
| name: String
120+
| following: [User!]! @relation(name: "UserToFollow", link: INLINE)
121+
| followers: [User!]! @relation(name: "UserToFollow")
122+
|}""".stripMargin
123+
}
124+
125+
database.setup(project2)
126+
127+
val a = server.query(s"""mutation{createUser(data:{name: "a", followers:{create:[{name:"b"}, {name:"c"}, {name:"x"}]}}){id}}""", project2)
128+
val d = server.query(s"""mutation{createUser(data:{name: "d", followers:{create:[{name:"e"}, {name:"f"}, {name:"x"}]}}){id}}""", project2)
129+
val g = server.query(s"""mutation{createUser(data:{name: "g", followers:{create:[{name:"h"}, {name:"i"}, {name:"x"}]}}){id}}""", project2)
130+
val k = server.query(s"""mutation{createUser(data:{name: "k", followers:{create:[{name:"l"}, {name:"m"}, {name:"x"}]}}){id}}""", project2)
131+
132+
val result = server.query(
133+
s"""{
134+
| usersConnection(where: {
135+
| followers_some: {
136+
| name: "x"
137+
| },
138+
| }, first: 2, after: "${a.pathAsString("data.createUser.id")}") {
139+
| edges {
140+
| node {
141+
| name
142+
| }
143+
| }
144+
| }
145+
|}""".stripMargin,
146+
project2
147+
)
148+
149+
result.toString should be("""{"data":{"usersConnection":{"edges":[{"node":{"name":"d"}},{"node":{"name":"g"}}]}}}""")
150+
151+
}
152+
153+
"the connection query" should "work when using cursors when not on Mongo" taggedAs (IgnoreMongo) in {
154+
155+
val project2 = SchemaDsl.fromStringV11() {
156+
"""type User {
157+
| id: ID! @id
158+
| name: String
159+
| following: [User!]! @relation(name: "UserToFollow", link: TABLE)
160+
| followers: [User!]! @relation(name: "UserToFollow")
161+
|}""".stripMargin
162+
}
163+
164+
database.setup(project2)
165+
166+
val a = server.query(s"""mutation{createUser(data:{name: "a", followers:{create:[{name:"b"}, {name:"c"}, {name:"x"}]}}){id}}""", project2)
167+
val d = server.query(s"""mutation{createUser(data:{name: "d", followers:{create:[{name:"e"}, {name:"f"}, {name:"x"}]}}){id}}""", project2)
168+
val g = server.query(s"""mutation{createUser(data:{name: "g", followers:{create:[{name:"h"}, {name:"i"}, {name:"x"}]}}){id}}""", project2)
169+
val k = server.query(s"""mutation{createUser(data:{name: "k", followers:{create:[{name:"l"}, {name:"m"}, {name:"x"}]}}){id}}""", project2)
170+
171+
val result = server.query(
172+
s"""{
173+
| usersConnection(where: {
174+
| followers_some: {
175+
| name: "x"
176+
| },
177+
| }, first: 2, after: "${a.pathAsString("data.createUser.id")}") {
178+
| edges {
179+
| node {
180+
| name
181+
| }
182+
| }
183+
| }
184+
|}""".stripMargin,
185+
project2
186+
)
187+
188+
result.toString should be("""{"data":{"usersConnection":{"edges":[{"node":{"name":"d"}},{"node":{"name":"g"}}]}}}""")
189+
190+
}
191+
111192
}

0 commit comments

Comments
 (0)