aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2022-01-02 00:23:07 +0530
committerArun Isaac2022-01-02 00:23:07 +0530
commit0af412019526f679f7e5d690c0598d24d714956c (patch)
treef72a0758ffe9c0863a21d19b07efd914ad9950fb
parent464b75248b42986cbf4150d11c9e080d0c99f78c (diff)
downloadkolam-0af412019526f679f7e5d690c0598d24d714956c.tar.gz
kolam-0af412019526f679f7e5d690c0598d24d714956c.tar.lz
kolam-0af412019526f679f7e5d690c0598d24d714956c.zip
kolam: Allow null value for types.
* kolam/graphql.scm (correct-type?): Allow null values for all types except non-nullable types.
-rw-r--r--kolam/graphql.scm12
1 files 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))))