[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/graphql da47d83cef 14/56: Add `graphql-{query, mutation
From: |
ELPA Syncer |
Subject: |
[elpa] externals/graphql da47d83cef 14/56: Add `graphql-{query, mutation}' macros |
Date: |
Sat, 29 Oct 2022 13:57:53 -0400 (EDT) |
branch: externals/graphql
commit da47d83cefe763d6dc5198bee4c56a32f4334116
Author: Sean Allred <code@seanallred.com>
Commit: Sean Allred <code@seanallred.com>
Add `graphql-{query,mutation}' macros
---
graphql.el | 44 ++++++++++++++++++++++++++++++++++++++++++++
test/graphql.el-test.el | 5 +++++
2 files changed, 49 insertions(+)
diff --git a/graphql.el b/graphql.el
index 3b40ff9e53..06e88e04ba 100644
--- a/graphql.el
+++ b/graphql.el
@@ -126,6 +126,50 @@ parameter."
(format " { %s }"
(mapconcat #'graphql-encode fields " ")))))))))
+(defun graphql--genform-operation (args kind)
+ (pcase args
+ (`(,graph)
+ `(graphql-encode '(,kind ,graph)))
+
+ (`((,name) ,graph)
+ `(graphql-encode '(,kind :op-name ,name
+ ,graph)))
+ (`((,name ,parameters) ,graph)
+ `(graphql-encode '(,kind :op-name ,name
+ :op-params ,parameters
+ ,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'."
+ (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'."
+ (graphql--genform-operation args 'query))
(provide 'graphql)
;;; graphql.el ends here
diff --git a/test/graphql.el-test.el b/test/graphql.el-test.el
index 457bb7f5f2..743e86d313 100644
--- a/test/graphql.el-test.el
+++ b/test/graphql.el-test.el
@@ -45,4 +45,9 @@
(content . HOORAY))))))
"addReaction(input:{subjectId:\"MDU6SXNzdWUxNzc2MzA3Mjk=\",content:HOORAY})")))
+(ert-deftest encode-query ()
+ (string= (graphql-query (test ((ep Episode !)
+ (review ReviewInput ! . "fifty")))
+ (repository))
+ "query test($ep: Episode!,$review: ReviewInput! = \"fifty\") {
repository }"))
;;; graphql.el-test.el ends here
- [elpa] externals/graphql f9dc451ae6 18/56: Simplify object encoding, (continued)
- [elpa] externals/graphql f9dc451ae6 18/56: Simplify object encoding, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql 0756399fc9 22/56: Test unnamed query, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql b0bd6c5fd8 02/56: Create DSL and basic encoder, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql fcc32d3d71 03/56: Simplify handling of spacing optional elements, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql 3bf43e2ad1 05/56: Use real names of things, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql 24d278dd43 06/56: Add support for variables in object parameters, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql 4d2837ddbe 07/56: Fix format bug for :name, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql 210fed6a12 09/56: More appropriate name for `:name', ELPA Syncer, 2022/10/29
- [elpa] externals/graphql d299be77da 12/56: Tweak handling for numbers when encoding argument values., ELPA Syncer, 2022/10/29
- [elpa] externals/graphql 08fb4fcf12 13/56: Add support for operation parameters via `:op-params', ELPA Syncer, 2022/10/29
- [elpa] externals/graphql da47d83cef 14/56: Add `graphql-{query, mutation}' macros,
ELPA Syncer <=
- [elpa] externals/graphql 22a84b1b08 15/56: Fix issue if `:op-name' and `:arguments' are given to one object, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql f43b1da554 17/56: Fix *-parameter-spec behavior when REQUIRED is omitted, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql e66ffb7743 19/56: Test suite fixes, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql e755652074 23/56: Various metadata, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql 6afdd2c8c8 26/56: Update resources, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql df200ddcf5 25/56: New test to ensure we're on the correct tag, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql 03d5cc4c3c 27/56: New function graphql-simplify-response-edges, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql c17526d9cd 31/56: Fix compile issues, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql 85eac3bbc2 20/56: Rename test file, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql b5a9df03ac 28/56: Separate top-level code-blocks with empty lines, ELPA Syncer, 2022/10/29