51
51
:tag " GraphQL"
52
52
:group 'languages )
53
53
54
+ (defcustom graphql-async t
55
+ " If non-nil, requests will be done asynchronously."
56
+ :tag " GraphQL"
57
+ :type 'boolean
58
+ :safe 'booleanp
59
+ :group 'graphql )
60
+
54
61
(defcustom graphql-indent-level 2
55
62
" Number of spaces for each indentation step in `graphql-mode' ."
56
63
:tag " GraphQL"
@@ -146,8 +153,9 @@ Please install it and try again."))
146
153
:type " POST"
147
154
:data body
148
155
:headers headers
149
- :parser 'json-read
150
- :sync t
156
+ :parser 'buffer-string
157
+ :sync (not graphql-async)
158
+ :success #'graphql--success-callback
151
159
:complete (lambda (&rest _ )
152
160
(message " %s " (if (string-equal " " operation)
153
161
url
@@ -157,7 +165,8 @@ Please install it and try again."))
157
165
(defun graphql-beginning-of-query ()
158
166
" Move the point to the beginning of the current query."
159
167
(interactive )
160
- (goto-char (syntax-ppss-toplevel-pos (syntax-ppss (point-at-bol ))))
168
+ (goto-char (or (syntax-ppss-toplevel-pos (syntax-ppss (point-at-bol )))
169
+ (point-min )))
161
170
(back-to-indentation ))
162
171
163
172
(defun graphql-end-of-query ()
@@ -224,6 +233,21 @@ Please install it and try again."))
224
233
(define-key map (kbd " q" ) 'quit-window )
225
234
map))
226
235
236
+ (cl-defun graphql--success-callback (&key response &allow-other-keys )
237
+ (with-current-buffer-window
238
+ " *GraphQL*" 'display-buffer-pop-up-window nil
239
+ (erase-buffer )
240
+ (when (fboundp 'json-mode )
241
+ (json-mode))
242
+ (insert (request-response-data response))
243
+ (json-pretty-print-buffer )
244
+ (goto-char (point-max ))
245
+ (insert " \n\n "
246
+ (propertize (request-response--raw-header response)
247
+ 'face 'font-lock-comment-face
248
+ 'font-lock-face 'font-lock-comment-face ))
249
+ (graphql-query-response-mode)))
250
+
227
251
(defun graphql-send-query ()
228
252
" Send the current GraphQL query/mutation/subscription to server."
229
253
(interactive )
@@ -234,27 +258,14 @@ Please install it and try again."))
234
258
235
259
(let* ((query (buffer-substring-no-properties (point-min ) (point-max )))
236
260
(operation (graphql-current-operation))
237
- (variables (graphql-current-variables var))
238
- (response (graphql--query query operation variables)))
239
- (with-current-buffer-window
240
- " *GraphQL*" 'display-buffer-pop-up-window nil
241
- (erase-buffer )
242
- (when (fboundp 'json-mode )
243
- (json-mode))
244
- (insert (json-encode (request-response-data response)))
245
- (json-pretty-print-buffer )
246
- (goto-char (point-max ))
247
- (insert " \n\n "
248
- (propertize (request-response--raw-header response)
249
- 'face 'font-lock-comment-face
250
- 'font-lock-face 'font-lock-comment-face ))
251
- (graphql-query-response-mode))))
261
+ (variables (graphql-current-variables var)))
262
+ (graphql--query query operation variables))
252
263
; ; If the query was successful, then save the value of graphql-url
253
264
; ; in the current buffer (instead of the introduced local
254
265
; ; binding).
255
266
(setq graphql-url url)
256
267
(setq graphql-variables-file var)
257
- nil ))
268
+ nil )))
258
269
259
270
(defvar graphql-mode-map
260
271
(let ((map (make-sparse-keymap )))
0 commit comments