emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/graphql-mode 052491e05f 048/122: update variable encoding


From: ELPA Syncer
Subject: [nongnu] elpa/graphql-mode 052491e05f 048/122: update variable encoding in post body, ask operation Name if needed
Date: Sat, 29 Jan 2022 08:03:32 -0500 (EST)

branch: elpa/graphql-mode
commit 052491e05f05c37dbbd9e3553cb4e38936f92d83
Author: Tim Shiu <punshiu@fb.com>
Commit: Tim Shiu <punshiu@fb.com>

    update variable encoding in post body, ask operation Name if needed
---
 graphql-mode.el | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/graphql-mode.el b/graphql-mode.el
index 04b2217ff1..a6b5df221d 100644
--- a/graphql-mode.el
+++ b/graphql-mode.el
@@ -77,21 +77,25 @@ response from the server."
         (setq url (concat url "&operationName=" operation)))
     (if variables
         (setq url (concat url "&variables=" (url-encode-url variables))))
-    (with-temp-buffer (graphql-post-request url query operation variables))))
+    (with-temp-buffer (graphql-post-request graphql-url url query operation 
variables))))
 
-(defun graphql-post-request (url query operation variables)
+(defun graphql-post-request (host_path url query operation variables)
   "graphql make post request to graphql endpoint url with body of query, 
operationName, and variables"
   (let* ((body (list (cons "query" query)
                      (cons "operationName" operation)
-                     (cons "variables" (json-encode variables))))
-         (response (request
+                     (cons "variables" variables)))
+         (response nil))
+    (setq response (request
                     url
                     :type "POST"
                     :data (json-encode body)
                     :headers '(("Content-Type" . "application/json"))
                     :parser 'json-read
                     :sync t
-                    )))
+                    :complete (lambda (&rest _)
+                                (message "%s" (if (string-equal "" operation)
+                                                  host_path
+                                                (format "%s?operationName=%s" 
host_path operation))))))
     (json-encode (request-response-data response))))
 
 (defun graphql-beginning-of-query ()
@@ -131,8 +135,8 @@ response from the server."
           (split-string query "[ \f\t\n\r\v]+"))
          (first (nth 0 tokens)))
 
-    (if (string-equal first "{")
-        nil
+    (if (or (string-equal first "{") (string-equal first ""))
+        (read-string "GraphQL operation: ")
       (replace-regexp-in-string "[({].*" "" (nth 1 tokens)))))
 
 (defun graphql-current-variables (filename)
@@ -142,14 +146,15 @@ response from the server."
            (not (file-directory-p filename))
            (file-exists-p filename))
       (condition-case nil
-          (json-encode (json-read-file filename))
+          (progn (display-buffer (find-file-noselect filename))
+                 (json-encode (json-read-file filename)))
         (error nil))
     nil))
 
 (defun graphql-send-query ()
   (interactive)
   (let* ((url (or graphql-url (read-string "GraphQL URL: " )))
-         (var (or graphql-variables (read-file-name "Variables File: "))))
+         (var (or graphql-variables (read-file-name "GraphQL Variables: "))))
     (let ((graphql-url url)
           (graphql-variables var))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]