Skip to content

Commit 6c71076

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

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
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

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)