[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/graphql 03d5cc4c3c 27/56: New function graphql-simplify
From: |
ELPA Syncer |
Subject: |
[elpa] externals/graphql 03d5cc4c3c 27/56: New function graphql-simplify-response-edges |
Date: |
Sat, 29 Oct 2022 13:57:56 -0400 (EDT) |
branch: externals/graphql
commit 03d5cc4c3c834f69288f49b1b97130e73ea94d00
Author: Sean Allred <code@seanallred.com>
Commit: Sean Allred <code@seanallred.com>
New function graphql-simplify-response-edges
GraphQL APIs will return networked objects in terms of 'edges' and
'nodes'. This function detects those relationships in a response data
structure and collapses them into just the value of each 'node'.
For instance, if I had a data structure like this:
(some_object (edges ((node (prop . "value")))
((node (prop . "other")))))
the simplification would look like this:
(some_object ((prop . "value"))
((prop . "other"))
Of course, this will work recursively and descend into fields and
subfields to simplify all edges it finds.
This does have the side-effect of removing pagination utilities like
the 'cursor' field of an edge, but that is a complex problem all its
own and it's probably best if this information is retrieved by other
means.
---
graphql.el | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/graphql.el b/graphql.el
index 5c2ef15881..3fb34191bf 100644
--- a/graphql.el
+++ b/graphql.el
@@ -134,6 +134,24 @@ parameter."
(format "{%s}"
(mapconcat #'graphql-encode fields " "))))))))
+(defun graphql-simplify-response-edges (data)
+ "Simplify DATA to collapse edges into their nodes."
+ (pcase data
+ ;; When we encounter a collection of edges, simplify those edges
+ ;; into their nodes
+ (`(,object (edges . ,edges))
+ (cons object (mapcar #'graphql-simplify-response-edges
+ (mapcar (lambda (edge) (alist-get 'node edge))
+ edges))))
+ ;; When we encounter a plain cons cell (not a list), let it pass
+ (`(,key . ,(and value (guard (not (consp value)))))
+ data)
+ ;; symbols should pass unaltered
+ (`,(and symbol (guard (symbolp symbol)))
+ data)
+ ;; everything else should be mapped
+ (_ (mapcar #'graphql-simplify-response-edges data))))
+
(defun graphql--genform-operation (args kind)
(pcase args
(`(,graph)
- [elpa] externals/graphql 210fed6a12 09/56: More appropriate name for `:name', (continued)
- [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, 2022/10/29
- [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 <=
- [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
- [elpa] externals/graphql 164e1b021c 30/56: Merge pull request #1 from tarsius/fixup, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql f5660677d9 35/56: Add documentation, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql f32ffec1a2 37/56: Change macro syntax to be slightly more natural, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql 2056967feb 38/56: More docstrings, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql 72f8c90334 40/56: Merge pull request #2 from tarsiiformes/minor, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql df311b3e31 42/56: Remove '$' from planned features; it is implemented in README, ELPA Syncer, 2022/10/29
- [elpa] externals/graphql 82354bb5af 45/56: Run lints as part of CI, ELPA Syncer, 2022/10/29