aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kolam/graphql.scm19
1 files changed, 13 insertions, 6 deletions
diff --git a/kolam/graphql.scm b/kolam/graphql.scm
index 676caa4..c8cc706 100644
--- a/kolam/graphql.scm
+++ b/kolam/graphql.scm
@@ -139,12 +139,19 @@
(eval-graphql tree (schema-query schema)))
(operation (error "Invalid GraphQL operation:" operation))))
+(define (tree->root+alias+args+children tree)
+ (let ((root children (match tree
+ ((root children ...) (values root children))
+ (leaf (values leaf #f)))))
+ (match root
+ (#((? symbol? root) (? symbol? alias) args ...)
+ (values root alias args children))
+ (#((? symbol? root) args ...)
+ (values root #f args children))
+ (root (values root #f '() children)))))
+
(define* (eval-graphql tree parent-type #:optional parent)
- (let* ((root args children (match tree
- ((#(root args ...) children ...) (values root args children))
- ((root children ...) (values root '() children))
- (#(leaf args ...) (values leaf args #f))
- (leaf (values leaf '() #f))))
+ (let* ((root alias args children (tree->root+alias+args+children tree))
;; TODO: Check if required args are present.
(root-field (or (find-field parent-type root)
(error "Unknown field:" root)))
@@ -161,7 +168,7 @@
(not (or (scalar-type? underlying-type)
(enum-type? underlying-type))))
(error "Leaf node must be scalar or enum type:" root-field underlying-type))
- (cons root
+ (cons (or alias root)
(cond
((eq? next-parent 'null) 'null)
;; List of non-object types