-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Input object null fields validation (#1090)
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
core/src/test/scala/caliban/validation/InputObjectSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package caliban.validation | ||
|
||
import caliban.CalibanError | ||
import caliban.GraphQL._ | ||
import caliban.RootResolver | ||
import zio.test.Assertion._ | ||
import zio.test._ | ||
import zio.test.environment.TestEnvironment | ||
|
||
object InputObjectSpec extends DefaultRunnableSpec { | ||
override def spec: ZSpec[TestEnvironment, Any] = | ||
suite("InputObjectSpec")( | ||
testM("fails if a non-null field on an input object is null") { | ||
val query = | ||
"""query { | ||
| query(input: {string: null}) | ||
|}""".stripMargin | ||
|
||
case class TestInputObject(string: String) | ||
case class TestInput(input: TestInputObject) | ||
case class Query(query: TestInput => String) | ||
val gql = graphQL(RootResolver(Query(_.input.string))) | ||
|
||
for { | ||
int <- gql.interpreter | ||
res <- int.execute(query) | ||
} yield assert(res.errors.headOption)( | ||
isSome((isSubtype[CalibanError.ValidationError](anything))) | ||
) | ||
} | ||
) | ||
} |