Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ sealed class NadelHydrationCondition {
}
}

data class BooleanResultEquals(
override val fieldPath: NadelQueryPath,
val value: Boolean,
) : NadelHydrationCondition() {
override fun evaluate(fieldValue: Any?): Boolean {
return fieldValue is Boolean && fieldValue == value
}
}

data class StringResultMatches(
override val fieldPath: NadelQueryPath,
val regex: Regex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,14 @@ data class NadelHydrationResultConditionUnsupportedFieldTypeError(
val str = Scalars.GraphQLString.name
val int = Scalars.GraphQLInt.name
val id = Scalars.GraphQLID.name
val boolean = Scalars.GraphQLBoolean.name
val parentTypeName = parentType.overall.name

getHydrationErrorMessage(
parentType,
virtualField,
hydration,
reason = "condition field $parentTypeName.$conditionField must be of type $str, $int, $id or enum but is $conditionFieldType",
reason = "condition field $parentTypeName.$conditionField must be of type $str, $int, $id, $boolean or enum but is $conditionFieldType",
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package graphql.nadel.validation.hydration

import graphql.Scalars.GraphQLBoolean
import graphql.Scalars.GraphQLID
import graphql.Scalars.GraphQLInt
import graphql.Scalars.GraphQLString
Expand Down Expand Up @@ -57,6 +58,10 @@ private sealed class NadelConditionFieldType {
override val graphQLType = GraphQLID
}

object BooleanType : NadelConditionFieldType() {
override val graphQLType = GraphQLBoolean
}

data class EnumType(
val enumType: GraphQLEnumType,
) : NadelConditionFieldType() {
Expand Down Expand Up @@ -134,6 +139,7 @@ internal class NadelHydrationConditionValidation {
GraphQLString -> NadelConditionFieldType.StringType
GraphQLInt -> NadelConditionFieldType.IntType
GraphQLID -> NadelConditionFieldType.IdType
GraphQLBoolean -> NadelConditionFieldType.BooleanType
is GraphQLEnumType -> NadelConditionFieldType.EnumType(conditionFieldOutputType)
else -> null
} ?: return NadelHydrationResultConditionUnsupportedFieldTypeError(
Expand Down Expand Up @@ -304,6 +310,11 @@ internal class NadelHydrationConditionValidation {
fieldPath = NadelQueryPath(resultCondition.pathToSourceField),
value = expectedValue.toLong(),
).asInterimSuccess()
} else if (expectedValue is Boolean && conditionFieldType == NadelConditionFieldType.BooleanType) {
return NadelHydrationCondition.BooleanResultEquals(
fieldPath = NadelQueryPath(resultCondition.pathToSourceField),
value = expectedValue,
).asInterimSuccess()
} else {
return NadelHydrationConditionIncompatibleValueError(
parentType = parent,
Expand Down
Loading
Loading