-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable feature by default with an overridable flag
- Loading branch information
Showing
8 changed files
with
116 additions
and
46 deletions.
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
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
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
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
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
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
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
49 changes: 49 additions & 0 deletions
49
core/src/test/scala/caliban/schema/SemanticNonNullSchemaSpec.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,49 @@ | ||
package caliban.schema | ||
|
||
import caliban._ | ||
import caliban.introspection.adt.{ __DeprecatedArgs, __Field } | ||
import caliban.parsing.adt.Directive | ||
import caliban.schema.Annotations._ | ||
import zio._ | ||
import zio.test.Assertion._ | ||
import zio.test._ | ||
|
||
object SemanticNonNullSchema extends SchemaDerivation[Any] { | ||
override def enableSemanticNonNull: Boolean = true | ||
} | ||
|
||
object SemanticNonNullSchemaSpec extends ZIOSpecDefault { | ||
override def spec = | ||
suite("SemanticNonNullSchemaSpec")( | ||
test("effectful field as semanticNonNull") { | ||
assert(effectfulFieldObjectSchema.toType_().fields(__DeprecatedArgs()).toList.flatten.headOption)( | ||
isSome( | ||
hasField[__Field, Option[List[Directive]]]( | ||
"directives", | ||
_.directives, | ||
isSome(contains((Directive("semanticNonNull")))) | ||
) | ||
) | ||
) | ||
}, | ||
test("optional effectful field") { | ||
assert(optionalEffectfulFieldObjectSchema.toType_().fields(__DeprecatedArgs()).toList.flatten.headOption)( | ||
isSome( | ||
hasField[__Field, Option[List[Directive]]]( | ||
"directives", | ||
_.directives.map(_.filter(_.name == "semanticNonNull")).filter(_.nonEmpty), | ||
isNone | ||
) | ||
) | ||
) | ||
} | ||
) | ||
|
||
case class EffectfulFieldObject(q: Task[Int], @GQLNonNullable qAnnotated: Task[Int]) | ||
case class OptionalEffectfulFieldObject(q: Task[Option[String]], @GQLNonNullable qAnnotated: Task[Option[String]]) | ||
|
||
implicit val effectfulFieldObjectSchema: Schema[Any, EffectfulFieldObject] = | ||
SemanticNonNullSchema.gen[Any, EffectfulFieldObject] | ||
implicit val optionalEffectfulFieldObjectSchema: Schema[Any, OptionalEffectfulFieldObject] = | ||
SemanticNonNullSchema.gen[Any, OptionalEffectfulFieldObject] | ||
} |