|
1 | 1 | package com.prisma.api.queries
|
2 | 2 |
|
| 3 | +import com.prisma.{IgnoreMongo, IgnoreMySql, IgnorePostgres, IgnoreSQLite} |
3 | 4 | import com.prisma.api.ApiSpecBase
|
4 | 5 | import com.prisma.shared.schema_dsl.SchemaDsl
|
5 | 6 | import org.scalatest.{FlatSpec, Matchers}
|
6 | 7 |
|
7 | 8 | class MultiItemConnectionQuerySpec extends FlatSpec with Matchers with ApiSpecBase {
|
| 9 | + |
8 | 10 | val project = SchemaDsl.fromStringV11() {
|
9 | 11 | """type Todo {
|
10 | 12 | | id: ID! @id
|
@@ -108,4 +110,83 @@ class MultiItemConnectionQuerySpec extends FlatSpec with Matchers with ApiSpecBa
|
108 | 110 | )
|
109 | 111 | .toString should equal("""{"data":{"todoesConnection":{"edges":[{"node":{"title":"Hello World!"}}]}}}""")
|
110 | 112 | }
|
| 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 | + |
111 | 192 | }
|
0 commit comments