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 5, 2024
1 parent 2d5d645 commit 6784705
Show file tree
Hide file tree
Showing 4 changed files with 80 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 munit = Seq("org.scalameta" %% "munit" % "1.0.0" % Test)
// ### App Modules ###

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

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,22 @@
import poc.caliban.posts.GraphQLApi

import scala.io.Source
import munit.FunSuite
import java.io.File
import java.nio.file.{Files, Paths}

class ValidateGraphQLTest extends FunSuite {

if (scala.util.Properties.versionNumberString.startsWith("3.")) {
test("validate postservice.graphql for scala 3") {
val filename = "postservice_scala3.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)

assertEquals(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 6784705

Please sign in to comment.