Skip to content

Commit

Permalink
Added test for validation of graphql schema
Browse files Browse the repository at this point in the history
  • Loading branch information
develeon committed Sep 8, 2024
1 parent 5904ded commit 55e581d
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ lazy val sttp = Seq(
"com.softwaremill.sttp.client3" %% "zio" % "3.9.8"
)

lazy val zioTest = Seq("dev.zio" %% "zio-test" % "2.1.9" % Test)
// ### App Modules ###

/**
Expand Down Expand Up @@ -103,7 +104,7 @@ lazy val posts =
)
)
)
.settings(libraryDependencies ++= calibanLib)
.settings(libraryDependencies ++= calibanLib ++ zioTest)

lazy val potatoes =
project
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
schema {
query: Query
mutation: Mutation
subscription: Subscription
}
scalar Unit

input AuthorNameInput {
name: String!
}

input PostContentInput {
content: String!
}

input PostTitleInput {
title: String!
}

type AuthorName {
name: String!
}

type Mutation {
createPost(authorName: AuthorNameInput!, title: PostTitleInput!, content: PostContentInput!): Post
deletePost(id: ID!): Unit
}

type Post {
id: PostId!
author: AuthorName!
title: PostTitle!
content: PostContent!
}

type PostContent {
content: String!
}

type PostId {
id: ID!
}

type PostTitle {
title: String!
}

type Query {
postById(id: ID!): Post
}

type Subscription {
allPostsByAuthor(name: String!): Post
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import poc.caliban.posts.GraphQLApi

import scala.io.Source
import java.io.File
import java.nio.file.{Files, Paths}
import zio.test.Assertion._
import zio.test._

class ValidateGraphQlSpec extends ZIOSpecDefault {

override def spec =
suite("Validate Postservice")(
test("Render postservice as earlier") {
val filename = "postservice.graphql"
val expectedGraphQL: String = Source.fromResource(filename).getLines().mkString("\n")
val gqlApi = GraphQLApi.api
val renderContent: String = s"${gqlApi.render}"

//Files.writeString(Paths.get(File(s"/tmp/$filename").toURI), renderContent)

assertTrue(expectedGraphQL == renderContent)
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,5 @@ $ exists modules/potatoes-clients/src/main/scala/poc/caliban/client/generated/po
-$ newer modules/posts/target/ctCalibanServer/touch modules/posts/target/ctCalibanServer/touch_old
# TODO: This should be newer, sadly I don't find how to make it work.
-$ 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

> reload; test

0 comments on commit 55e581d

Please sign in to comment.