|
| 1 | +package com.prisma.api.queries |
| 2 | + |
| 3 | +import com.prisma.api.ApiSpecBase |
| 4 | +import com.prisma.shared.schema_dsl.SchemaDsl |
| 5 | +import org.scalatest.{FlatSpec, Matchers} |
| 6 | + |
| 7 | +class RelationFilterOrderingSpec extends FlatSpec with Matchers with ApiSpecBase { |
| 8 | + |
| 9 | + "Using relational filters" should "return items in the specified order" in { |
| 10 | + |
| 11 | + val project = SchemaDsl.fromStringV11() { |
| 12 | + """type Blog { |
| 13 | + | id: ID! @id |
| 14 | + | title: String! |
| 15 | + | score: Int! |
| 16 | + | labels: [Label!]! @relation(name: "BlogLabels", link: INLINE) |
| 17 | + |} |
| 18 | + |type Label { |
| 19 | + | id: ID! @id |
| 20 | + | text: String! @unique |
| 21 | + |}""" |
| 22 | + } |
| 23 | + |
| 24 | + database.setup(project) |
| 25 | + |
| 26 | + server.query(s"""mutation {createLabel(data: {text: "x"}) {text }}""", project) |
| 27 | + |
| 28 | + server.query(s"""mutation {createBlog(data: {title: "blog_1", score: 10,labels: {connect: {text: "x"}}}) {title}}""", project) |
| 29 | + server.query(s"""mutation {createBlog(data: {title: "blog_1", score: 20,labels: {connect: {text: "x"}}}) {title}}""", project) |
| 30 | + server.query(s"""mutation {createBlog(data: {title: "blog_1", score: 30,labels: {connect: {text: "x"}}}) {title}}""", project) |
| 31 | + |
| 32 | + val res1 = server.query("""query {blogs(first: 2, orderBy: score_DESC) {title, score}}""", project) |
| 33 | + |
| 34 | + res1.toString should be("""{"data":{"blogs":[{"title":"blog_1","score":30},{"title":"blog_1","score":20}]}}""") |
| 35 | + |
| 36 | + val res2 = server.query("""query {blogs (first: 2, orderBy: score_DESC, where:{labels_some: {text: "x"}}) {title, score}}""", project) |
| 37 | + res2.toString should be("""{"data":{"blogs":[{"title":"blog_1","score":30},{"title":"blog_1","score":20}]}}""") |
| 38 | + |
| 39 | + } |
| 40 | +} |
0 commit comments