Skip to content

Commit

Permalink
Adds tests for checking deprecated args for derived schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
hwielenberg committed Jul 24, 2024
1 parent ce502f6 commit 9a18e0b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ lazy val tools = project
"dev.zio" %% "zio-json" % zioJsonVersion % Test
)
)
.dependsOn(core, clientJVM)
.dependsOn(core, clientJVM, quickAdapter % "test")

lazy val tracing = project
.in(file("tracing"))
Expand Down
52 changes: 52 additions & 0 deletions tools/src/test/scala/caliban/tools/IntrospectionClientSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package caliban.tools

import caliban._
import caliban.quick._
import caliban.schema.Annotations._
import caliban.schema.Schema.auto._
import caliban.schema.ArgBuilder.auto._
import zio.test._
import zio.{Clock, durationInt}

object IntrospectionClientSpec extends ZIOSpecDefault {

case class Args(@GQLDeprecated("Use nameV2") name:Option[String] = Some("defaultValue"), nameV2:String)

case class Queries(
getObject: Args => String
)

object Resolvers {
def getObject(@GQLDeprecated("foobar") args: Args): String =
args.name.getOrElse("")
}

val queries = Queries(
getObject = Resolvers.getObject
)

val api = graphQL(
RootResolver(
queries
)
)

def spec = suite("IntrospectionClientSpec")(
test("is isomorphic") {
for {
_ <- api.runServer(
port = 8087,
apiPath = "/api/graphql",
).fork
_ <- Clock.ClockLive.sleep(2.seconds)
introspectedSchema = SchemaLoader.fromIntrospection("http://localhost:8087/api/graphql", None)
codeSchema = SchemaLoader.fromCaliban(api)
res <- SchemaComparison.compare(
introspectedSchema,
codeSchema
)
} yield assertTrue(res.isEmpty, false)
}
)

}
18 changes: 13 additions & 5 deletions tools/src/test/scala/caliban/tools/RemoteSchemaSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import caliban._
import caliban.introspection.adt._
import caliban.schema._
import caliban.schema.Schema.auto._
import caliban.schema.ArgBuilder.auto._
import zio._
import zio.test.Assertion._
import zio.test._
import schema.Annotations._
import caliban.schema.Annotations._
import caliban.Macros.gqldoc
import caliban.execution.Feature
import caliban.transformers.Transformer


object RemoteSchemaSpec extends ZIOSpecDefault {
sealed trait EnumType extends Product with Serializable
case object EnumValue1 extends EnumType
Expand All @@ -20,6 +22,8 @@ object RemoteSchemaSpec extends ZIOSpecDefault {
sealed trait UnionType extends Product with Serializable
case class UnionValue1(field: String) extends UnionType

case class Args(@GQLDeprecated("Use nameV2") name:String = "defaultValue", nameV2:String)

case class Object(
field: Int,
optionalField: Option[Float],
Expand All @@ -29,7 +33,7 @@ object RemoteSchemaSpec extends ZIOSpecDefault {
)

object Resolvers {
def getObject(arg: String = "defaultValue"): Object =
def getObject(@GQLDeprecated("fooBar") args: Args): Object =
Object(
field = 1,
optionalField = None,
Expand All @@ -39,7 +43,7 @@ object RemoteSchemaSpec extends ZIOSpecDefault {
}

case class Queries(
getObject: String => Object
getObject: Args => Object
)

val queries = Queries(
Expand All @@ -52,15 +56,19 @@ object RemoteSchemaSpec extends ZIOSpecDefault {
)
)

def spec = suite("ParserSpec")(
def spec = suite("RemoteSchemaSpec")(
test("is isomorphic") {
for {
introspected <- SchemaLoader.fromCaliban(api).load
remoteSchema <- ZIO.fromOption(RemoteSchema.parseRemoteSchema(introspected))
remoteAPI <- ZIO.succeed(fromRemoteSchema(remoteSchema))
sdl = api.render
remoteSDL = remoteAPI.render
} yield assertTrue(remoteSDL == sdl)
res <- SchemaComparison.compare(
SchemaLoader.fromCaliban(api),
SchemaLoader.fromCaliban(remoteAPI)
)
} yield assertTrue(res.isEmpty, remoteSDL == sdl)
},
test("properly resolves interface types") {
@GQLInterface
Expand Down

0 comments on commit 9a18e0b

Please sign in to comment.