From 5c20b5046c54d0cda6d47c52418b4373296ca0bf Mon Sep 17 00:00:00 2001 From: XiNiHa Date: Sat, 11 May 2024 19:06:33 +0900 Subject: [PATCH] Fix not keeping semantics of .optional on custom schema --- core/src/main/scala-2/caliban/schema/SchemaDerivation.scala | 2 +- core/src/main/scala-3/caliban/schema/DerivationUtils.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala b/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala index ef87048eb..1dc9c7038 100644 --- a/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala +++ b/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala @@ -100,7 +100,7 @@ trait CommonSchemaDerivation[R] { val hasNonNullAnn = p.annotations.contains(GQLNonNullable()) if (hasNonNullAnn) (false, false) - else if (hasNullableAnn || p.typeclass.nullable) (true, false) + else if ((hasNullableAnn || p.typeclass.optional) && !p.typeclass.canFail) (true, false) else if (p.typeclass.canFail) (true, true) else (false, false) } diff --git a/core/src/main/scala-3/caliban/schema/DerivationUtils.scala b/core/src/main/scala-3/caliban/schema/DerivationUtils.scala index 538df7242..88f787dab 100644 --- a/core/src/main/scala-3/caliban/schema/DerivationUtils.scala +++ b/core/src/main/scala-3/caliban/schema/DerivationUtils.scala @@ -132,7 +132,7 @@ private object DerivationUtils { val hasNonNullAnn = fieldAnnotations.contains(GQLNonNullable()) if (hasNonNullAnn) (false, false) - else if (hasNullableAnn || schema.nullable) (true, false) + else if ((hasNullableAnn || schema.optional) && !schema.canFail) (true, false) else if (schema.canFail) (true, true) else (false, false) }