branch: externals/graphql
commit f32ffec1a225d3222c8ba36ef0538dbf3008ba6b
Author: Sean Allred <c...@seanallred.com>
Commit: Sean Allred <c...@seanallred.com>

    Change macro syntax to be slightly more natural
---
 graphql.el           | 35 +++++++++--------------------------
 test/graphql-test.el | 16 ++++++++--------
 2 files changed, 17 insertions(+), 34 deletions(-)

diff --git a/graphql.el b/graphql.el
index 0d43955c69..cedb418974 100644
--- a/graphql.el
+++ b/graphql.el
@@ -160,47 +160,30 @@ parameter."
 
 (defun graphql--genform-operation (args kind)
   (pcase args
-    (`(,graph)
-     `(graphql-encode '(,kind ,@graph)))
-
-    (`((,name) ,graph)
+    (`(,name ,parameters ,graph)
      `(graphql-encode '(,kind :op-name ,name
+                              :op-params ,parameters
                               ,@graph)))
-    (`((,name ,parameters) ,graph)
+
+    (`(,name ,graph)
      `(graphql-encode '(,kind :op-name ,name
-                              :op-params ,parameters
                               ,@graph)))
 
+    (`(,graph)
+     `(graphql-encode '(,kind ,@graph)))
+
     (_ (error "bad form"))))
 
 (defmacro graphql-query (&rest args)
   "Construct a Query object.
-Calling pattern:
-
-  (fn GRAPH) := Just encode GRAPH as a Query.
-
-  (fn (NAME) GRAPH) := Give the Query a NAME.
-
-  (fn (NAME PARAMETERS) GRAPH) := Give the Query PARAMETERS;
-                                  see below.
 
-Parameters are formatted as defined by
-`graphql--encode-parameter-spec'."
+\(fn [NAME] [(PARAMETER-SPEC...)] GRAPH)"
   (graphql--genform-operation args 'query))
 
 (defmacro graphql-mutation (&rest args)
   "Construct a Mutation object.
-Calling pattern:
-
-  (fn GRAPH) := Just encode GRAPH as a Mutation.
-
-  (fn (NAME) GRAPH) := Give the Mutation a NAME.
-
-  (fn (NAME PARAMETERS) GRAPH) := Give the Mutation PARAMETERS;
-                                  see below.
 
-Parameters are formatted as defined by
-`graphql--encode-parameter-spec'."
+\(fn [NAME] [(PARAMETER-SPEC...)] GRAPH)"
   (graphql--genform-operation args 'mutation))
 
 (provide 'graphql)
diff --git a/test/graphql-test.el b/test/graphql-test.el
index 2703f9cd3a..5145cc036f 100644
--- a/test/graphql-test.el
+++ b/test/graphql-test.el
@@ -64,22 +64,22 @@
 (ert-deftest encode-query ()
   (should (string= (graphql-query (repository))
                    "query{repository}"))
-  (should (string= (graphql-query (test)
+  (should (string= (graphql-query test
                                   ((repository)))
                    "query test{repository}"))
-  (should (string= (graphql-query (test ((ep Episode !)
-                                         (review ReviewInput ! . 50)))
+  (should (string= (graphql-query test ((ep Episode !)
+                                        (review ReviewInput ! . 50))
                                   ((repository :arguments ((hello . ($ ep))))))
                    "query 
test($ep:Episode!,$review:ReviewInput!=50){repository(hello:$ep)}"))
-  (should (string= (graphql-mutation (testMutation ((ep Episode . ((complex . 
params)))))
+  (should (string= (graphql-mutation testMutation ((ep Episode . ((complex . 
params))))
                                      ((change thing)))
                    "mutation testMutation($ep:Episode!){change{thing}}")))
 
 (ert-deftest encode-complicated ()
-  (should (string= (graphql-query (test ((ep Episode . ((complex . params)
-                                                        (with . "values")
-                                                        (like . 50)))
-                                         (review ReviewInput ! . 50)))
+  (should (string= (graphql-query test ((ep Episode . ((complex . params)
+                                                       (with . "values")
+                                                       (like . 50)))
+                                        (review ReviewInput ! . 50))
                                   ((repository :arguments ((hello . ($ ep))))))
                    "query 
test($ep:Episode={complex:params,with:\"values\",like:50},$review:ReviewInput!=50){repository(hello:$ep)}")))
 ;;; graphql-test.el ends here

Reply via email to