[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/graphql-mode 22a4340ec3 044/122: add post body json suppor
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/graphql-mode 22a4340ec3 044/122: add post body json support: query, operationName, variables |
Date: |
Sat, 29 Jan 2022 08:03:31 -0500 (EST) |
branch: elpa/graphql-mode
commit 22a4340ec3e7d4adc9fc0d590abf506c4d0a33dc
Author: Tim Shiu <punshiu@fb.com>
Commit: Tim Shiu <punshiu@fb.com>
add post body json support: query, operationName, variables
---
graphql-mode.el | 51 +++++++++++++++++++++++----------------------------
1 file changed, 23 insertions(+), 28 deletions(-)
diff --git a/graphql-mode.el b/graphql-mode.el
index aa2dcb7afe..79d62df168 100644
--- a/graphql-mode.el
+++ b/graphql-mode.el
@@ -40,7 +40,7 @@
(require 'json)
(require 'url)
(require 'cl-lib)
-
+(require 'request)
;;; User Customizations:
@@ -56,7 +56,7 @@
:safe 'integerp
:group 'graphql)
-(defcustom graphql-url "http://localhost:8000/graphql"
+(defcustom graphql-url nil
"URL address of the graphql server endpoint."
:tag "GraphQL"
:type 'string
@@ -66,16 +66,27 @@
"Send QUERY to the server at `graphql-url' and return the
response from the server."
(let* ((url-request-method "POST")
- (query (url-encode-url query))
- (url (format "%s?query=%s" graphql-url query)))
+ (url (format "%s?query=%s" graphql-url (url-encode-url query))))
(if operation
(setq url (concat url "&operationName=" operation)))
(if variables
(setq url (concat url "&variables=" (url-encode-url variables))))
- (with-current-buffer (url-retrieve-synchronously url t)
- (goto-char (point-min))
- (search-forward "\n\n")
- (buffer-substring (point) (point-max)))))
+ (with-temp-buffer (graphql-post-request url query operation variables))))
+
+(defun graphql-post-request (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
+ url
+ :type "POST"
+ :data (json-encode body)
+ :headers '(("Content-Type" . "application/json"))
+ :parser 'json-read
+ :sync t
+ )))
+ (json-encode (request-response-data response))))
(defun graphql-beginning-of-query ()
"Move the point to the beginning of the current query."
@@ -119,30 +130,14 @@ response from the server."
(replace-regexp-in-string "[({].*" "" (nth 1 tokens)))))
(defun graphql-current-variables ()
- "get the content of graphql variables"
- (let ((variables
- (save-excursion
- (goto-char (point-max))
- (search-backward-regexp "^variables" (point-min) t)
- (search-forward-regexp "^variables" (point-max) t)
- (point))))
- (if (eq variables (point-max))
- nil
- (buffer-substring-no-properties variables (point-max)))))
-
-(defun graphql-beginning-of-variables ()
- "get the beginning point of graphql variables"
- (save-excursion
- (goto-char (point-max))
- (search-backward-regexp "^variables" (point-min) t)
- (beginning-of-line)
- (point)))
+ "get the content of graphql variables from a file"
+ nil)
(defun graphql-send-query ()
(interactive)
(let ((url (or graphql-url (read-string "GraphQL URL: " ))))
(let ((graphql-url url))
- (let* ((query (buffer-substring-no-properties (point-min)
(graphql-beginning-of-variables)))
+ (let* ((query (buffer-substring-no-properties (point-min) (point-max)))
(operation (graphql-current-operation))
(variables (graphql-current-variables))
(response (graphql--query query operation variables)))
@@ -190,7 +185,7 @@ response from the server."
(defvar graphql-definition-regex
- (concat "\\(" (regexp-opt '("type" "input" "interface" "fragment" "query"
"mutation" "variables" "subscription" "enum")) "\\)"
+ (concat "\\(" (regexp-opt '("type" "input" "interface" "fragment" "query"
"mutation" "subscription" "enum")) "\\)"
"[[:space:]]+\\(\\_<.+?\\_>\\)"))
(defvar graphql-builtin-types
- [nongnu] elpa/graphql-mode 0f2b4b1604 077/122: Merge branch 'next', (continued)
- [nongnu] elpa/graphql-mode 0f2b4b1604 077/122: Merge branch 'next', ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode d0a85fe1d3 067/122: Shorten long lines, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 7aa3532aed 026/122: Don't depend on json-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 0b41444096 028/122: Add installation notes, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 43434aa6d5 061/122: Format some docs and docstrings, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 8b2fe76635 057/122: fix a recursive bug in graphql-current-operation, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode f3cfd9fc1e 062/122: Don't send the query as a query parameter, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 301d2419a0 012/122: Prompt the user for the GraphQL, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 17c2150ff6 058/122: rebase branch 'queries support' into branch 'next', ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 83e3a73f21 033/122: Fix: don't add slash between url and query parameters, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 22a4340ec3 044/122: add post body json support: query, operationName, variables,
ELPA Syncer <=
- [nongnu] elpa/graphql-mode 41df2a3140 019/122: Add docstring for graphql-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode d5cfe9326c 074/122: Rename graphql-headers to graphql-extra-headers, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 5971b69c8c 076/122: Fix: respect local value of graphql-url when posting a request, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 5e7665dfc4 059/122: forget the actual changes, (I have two location to dev/test), ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 2326c1fb18 034/122: Merge pull request #7 from eoma/fix-url, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 04e56ae626 053/122: Disable json-mode for response temporarily, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode ab58192967 081/122: Merge pull request #23 from leoliu/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode c643d53a4b 083/122: Don't send operationName when operation is an empty string, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode 09a9af6c98 075/122: Merge remote-tracking branch 'origin/master' into next, ELPA Syncer, 2022/01/29
- [nongnu] elpa/graphql-mode b802f77542 068/122: graphql-send-query: Silence byte-compiler, ELPA Syncer, 2022/01/29