Skip to content

Commit 1b89638

Browse files
committed
feat: add GRAPHQL method support
1 parent 12f2ce7 commit 1b89638

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

lua/kulala/parser/request.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ local function set_headers(request)
250250
end
251251

252252
local function process_graphql(request)
253-
local is_graphql = PARSER_UTILS.contains_meta_tag(request, "graphql")
253+
local is_graphql = request.method == "GRAPHQL"
254+
or PARSER_UTILS.contains_meta_tag(request, "graphql")
254255
or PARSER_UTILS.contains_header(request.headers, "x-request-type", "graphql")
255256

256257
if request.body and #request.body > 0 and is_graphql then

scripts/tests.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
export TERM=xterm-color
4+
35
if ! command -v nvim &> /dev/null; then
46
echo "nvim is not installed"
57
exit 1
@@ -31,7 +33,7 @@ run() {
3133
if [[ -n $1 ]]; then
3234
nvim -l tests/minit.lua tests --filter "$1"
3335
else
34-
nvim -l tests/minit.lua tests
36+
nvim -l tests/minit.lua tests -o utfTerminal -Xoutput --color
3537
fi
3638
}
3739

tests/functional/requests_spec.lua

+33
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,39 @@ describe("requests", function()
416416
assert.has_string(request_body_computed, '"variables":{"id":1}')
417417
end)
418418

419+
it("runs GraphQL request method", function()
420+
curl.stub({
421+
["https://countries.trevorblades.com"] = {
422+
body = h.load_fixture("fixtures/graphql_schema_body.txt"),
423+
},
424+
})
425+
426+
h.create_buf(
427+
([[
428+
GRAPHQL https://countries.trevorblades.com
429+
430+
query Person($id: ID) {
431+
person(personID: $id) {
432+
name
433+
}
434+
}
435+
436+
{
437+
"id": 1
438+
}
439+
]]):to_table(true),
440+
"test.http"
441+
)
442+
443+
kulala.run()
444+
wait_for_requests(1)
445+
446+
local request_body_computed = DB.data.current_request.body_computed
447+
448+
assert.has_string(request_body_computed, '"query":"query Person($id: ID) { person(personID: $id) { name } }')
449+
assert.has_string(request_body_computed, '"variables":{"id":1}')
450+
end)
451+
419452
it("runs API callbacks", function()
420453
curl.stub({
421454
["https://httpbin.org/simple"] = {

0 commit comments

Comments
 (0)