about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2021-12-30 16:19:28 +0530
committerArun Isaac2021-12-30 16:20:19 +0530
commit602043b071085cfef2eabd19698fe8b54a574cee (patch)
tree89fb005deb81d74e430fd3b79300cd28a8a96094
parent17ec30cc63a805fed87742ec3f5824889a55aeb6 (diff)
downloadkolam-602043b071085cfef2eabd19698fe8b54a574cee.tar.gz
kolam-602043b071085cfef2eabd19698fe8b54a574cee.tar.lz
kolam-602043b071085cfef2eabd19698fe8b54a574cee.zip
kolam: Allow leaf nodes to be list types.
* kolam/graphql.scm (resolvable-type?): New function.
(eval-graphql): Allow leaf nodes to be list types.
-rw-r--r--kolam/graphql.scm14
1 files changed, 11 insertions, 3 deletions
diff --git a/kolam/graphql.scm b/kolam/graphql.scm
index c8cc706..59cc34f 100644
--- a/kolam/graphql.scm
+++ b/kolam/graphql.scm
@@ -150,6 +150,14 @@
        (values root #f args children))
       (root (values root #f '() children)))))
 
+(define (resolvable-type? type)
+  "Return non-#f if TYPE is fully resolvable, that is, it is composed
+of scalar types, enum types, or lists thereof."
+  (if (list-type? type)
+      (resolvable-type? (list-type-subtype type))
+      (or (scalar-type? type)
+          (enum-type? type))))
+
 (define* (eval-graphql tree parent-type #:optional parent)
   (let* ((root alias args children (tree->root+alias+args+children tree))
          ;; TODO: Check if required args are present.
@@ -165,9 +173,9 @@
       (error "Return value of resolver is of unexpected GraphQL type:"
              next-parent root-type))
     (when (and (not children)
-               (not (or (scalar-type? underlying-type)
-                        (enum-type? underlying-type))))
-      (error "Leaf node must be scalar or enum type:" root-field underlying-type))
+               (not (resolvable-type? underlying-type)))
+      (error "Leaf node must be a scalar type, an enum type, or lists thereof:"
+             root-field underlying-type))
     (cons (or alias root)
           (cond
            ((eq? next-parent 'null) 'null)