diff --git a/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala b/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala index 95ef702c7..eabecc03e 100644 --- a/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala +++ b/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala @@ -106,7 +106,7 @@ trait CommonSchemaDerivation[R] { Option( p.annotations.collect { case GQLDirective(dir) => dir }.toList ++ { if (enableSemanticNonNull && !isNullable && p.typeclass.canFail) - Some(Directive("semanticNonNull")) + Some(SchemaUtils.SemanticNonNull) else None } ).filter(_.nonEmpty) diff --git a/core/src/main/scala-3/caliban/schema/DerivationUtils.scala b/core/src/main/scala-3/caliban/schema/DerivationUtils.scala index 487024cd8..040b327b6 100644 --- a/core/src/main/scala-3/caliban/schema/DerivationUtils.scala +++ b/core/src/main/scala-3/caliban/schema/DerivationUtils.scala @@ -143,7 +143,7 @@ private object DerivationUtils { deprecatedReason, Option( getDirectives(fieldAnnotations) ++ { - if (enableSemanticNonNull && !isNullable && schema.canFail) Some(Directive("semanticNonNull")) + if (enableSemanticNonNull && !isNullable && schema.canFail) Some(SchemaUtils.SemanticNonNull) else None } ).filter(_.nonEmpty) diff --git a/core/src/main/scala/caliban/schema/SchemaUtils.scala b/core/src/main/scala/caliban/schema/SchemaUtils.scala index de0e571aa..4db3a4ca0 100644 --- a/core/src/main/scala/caliban/schema/SchemaUtils.scala +++ b/core/src/main/scala/caliban/schema/SchemaUtils.scala @@ -4,8 +4,14 @@ import caliban.ResponseValue.ObjectValue import caliban.Value.{ EnumValue, NullValue, StringValue } import caliban.introspection.adt.{ __DeprecatedArgs, __Field, __Type } import caliban.schema.Step.MetadataFunctionStep +import caliban.parsing.adt.Directive private[schema] object SchemaUtils { + /** + * Directive used to mark a field as semantically non-nullable. + */ + val SemanticNonNull = Directive("semanticNonNull") + private val fakeField = Some( List( diff --git a/core/src/test/scala/caliban/schema/SemanticNonNullSchemaSpec.scala b/core/src/test/scala/caliban/schema/SemanticNonNullSchemaSpec.scala index 3e89533f8..f65237c43 100644 --- a/core/src/test/scala/caliban/schema/SemanticNonNullSchemaSpec.scala +++ b/core/src/test/scala/caliban/schema/SemanticNonNullSchemaSpec.scala @@ -21,7 +21,7 @@ object SemanticNonNullSchemaSpec extends ZIOSpecDefault { hasField[__Field, Option[List[Directive]]]( "directives", _.directives, - isSome(contains((Directive("semanticNonNull")))) + isSome(contains(SchemaUtils.SemanticNonNull)) ) ) ) @@ -31,7 +31,7 @@ object SemanticNonNullSchemaSpec extends ZIOSpecDefault { isSome( hasField[__Field, Option[List[Directive]]]( "directives", - _.directives.map(_.filter(_.name == "semanticNonNull")).filter(_.nonEmpty), + _.directives.map(_.filter(_ == SchemaUtils.SemanticNonNull)).filter(_.nonEmpty), isNone ) )