Skip to content

Commit 6784705

Browse files
committed
Added test for validation of graphql schema
1 parent 2d5d645 commit 6784705

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

codegen-sbt/src/sbt-test/compiletime-codegen/test-compile/build.sbt

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ lazy val sttp = Seq(
3838
"com.softwaremill.sttp.client3" %% "zio" % "3.9.8"
3939
)
4040

41+
lazy val munit = Seq("org.scalameta" %% "munit" % "1.0.0" % Test)
4142
// ### App Modules ###
4243

4344
/**
@@ -103,7 +104,7 @@ lazy val posts =
103104
)
104105
)
105106
)
106-
.settings(libraryDependencies ++= calibanLib)
107+
.settings(libraryDependencies ++= calibanLib ++ munit)
107108

108109
lazy val potatoes =
109110
project
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
schema {
2+
query: Query
3+
mutation: Mutation
4+
subscription: Subscription
5+
}
6+
scalar Unit
7+
8+
input AuthorNameInput {
9+
name: String!
10+
}
11+
12+
input PostContentInput {
13+
content: String!
14+
}
15+
16+
input PostTitleInput {
17+
title: String!
18+
}
19+
20+
type AuthorName {
21+
name: String!
22+
}
23+
24+
type Mutation {
25+
createPost(authorName: AuthorNameInput!, title: PostTitleInput!, content: PostContentInput!): Post
26+
deletePost(id: ID!): Unit
27+
}
28+
29+
type Post {
30+
id: PostId!
31+
author: AuthorName!
32+
title: PostTitle!
33+
content: PostContent!
34+
}
35+
36+
type PostContent {
37+
content: String!
38+
}
39+
40+
type PostId {
41+
id: ID!
42+
}
43+
44+
type PostTitle {
45+
title: String!
46+
}
47+
48+
type Query {
49+
postById(id: ID!): Post
50+
}
51+
52+
type Subscription {
53+
allPostsByAuthor(name: String!): Post
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import poc.caliban.posts.GraphQLApi
2+
3+
import scala.io.Source
4+
import munit.FunSuite
5+
import java.io.File
6+
import java.nio.file.{Files, Paths}
7+
8+
class ValidateGraphQLTest extends FunSuite {
9+
10+
if (scala.util.Properties.versionNumberString.startsWith("3.")) {
11+
test("validate postservice.graphql for scala 3") {
12+
val filename = "postservice_scala3.graphql"
13+
val expectedGraphQL: String = Source.fromResource(filename).getLines().mkString("\n")
14+
val gqlApi = GraphQLApi.api
15+
val renderContent: String = s"${gqlApi.render}"
16+
17+
//Files.writeString(Paths.get(File(s"/tmp/$filename").toURI), renderContent)
18+
19+
assertEquals(expectedGraphQL, renderContent)
20+
}
21+
}
22+
}

codegen-sbt/src/sbt-test/compiletime-codegen/test-compile/test

+2
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,5 @@ $ exists modules/potatoes-clients/src/main/scala/poc/caliban/client/generated/po
201201
-$ newer modules/posts/target/ctCalibanServer/touch modules/posts/target/ctCalibanServer/touch_old
202202
# TODO: This should be newer, sadly I don't find how to make it work.
203203
-$ newer modules/posts-clients/target/scala-2.12/src_managed/main/poc/caliban/client/generated/posts/CalibanClient.scala modules/posts-clients/tmp/CalibanClient.scala.old
204+
205+
> reload; test

0 commit comments

Comments
 (0)