aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2021-12-28 23:24:02 +0530
committerArun Isaac2021-12-30 13:49:08 +0530
commit17ec30cc63a805fed87742ec3f5824889a55aeb6 (patch)
tree6f7f07b47dcffa468438e2edb40a7afd4068bebb
parentb20337396153d3ed6455b7b9458f9344858014c4 (diff)
downloadkolam-17ec30cc63a805fed87742ec3f5824889a55aeb6.tar.gz
kolam-17ec30cc63a805fed87742ec3f5824889a55aeb6.tar.lz
kolam-17ec30cc63a805fed87742ec3f5824889a55aeb6.zip
kolam: Support field alias.
* kolam/graphql.scm (tree->root+alias+args+children): New function. (eval-graphql): Call tree->root+alias+args+children and use the returned alias in the response.
-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