From 0af412019526f679f7e5d690c0598d24d714956c Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sun, 2 Jan 2022 00:23:07 +0530 Subject: kolam: Allow null value for types. * kolam/graphql.scm (correct-type?): Allow null values for all types except non-nullable types. --- kolam/graphql.scm | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kolam/graphql.scm b/kolam/graphql.scm index 59cc34f..0440f74 100644 --- a/kolam/graphql.scm +++ b/kolam/graphql.scm @@ -119,17 +119,19 @@ "Return non-#f if VALUE is of GraphQL TYPE. Else, return #f." (cond ((scalar-type? type) - ((scalar-type-predicate type) value)) + (or (eq? value 'null) + ((scalar-type-predicate type) value))) ((enum-type? type) (member value - (enum-type-enumerators type))) + (cons 'null (enum-type-enumerators type)))) ((non-nullable-type? type) (and (not (eq? value 'null)) (correct-type? value (non-nullable-type-subtype type)))) ((list-type? type) - (and (list? value) - (every (cut correct-type? <> (list-type-subtype type)) - value))) + (or (eq? value 'null) + (and (list? value) + (every (cut correct-type? <> (list-type-subtype type)) + value)))) ((object-type? type) #t) (else (error "Unknown type:" type)))) -- cgit v1.2.3