Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add GRAPHQL method support #423

Merged
merged 2 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lua/kulala/parser/request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ local function set_headers(request)
end

local function process_graphql(request)
local is_graphql = PARSER_UTILS.contains_meta_tag(request, "graphql")
local is_graphql = request.method == "GRAPHQL"
or PARSER_UTILS.contains_meta_tag(request, "graphql")
or PARSER_UTILS.contains_header(request.headers, "x-request-type", "graphql")

if request.body and #request.body > 0 and is_graphql then
Expand Down
4 changes: 3 additions & 1 deletion scripts/tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

export TERM=xterm-color

if ! command -v nvim &> /dev/null; then
echo "nvim is not installed"
exit 1
Expand Down Expand Up @@ -31,7 +33,7 @@ run() {
if [[ -n $1 ]]; then
nvim -l tests/minit.lua tests --filter "$1"
else
nvim -l tests/minit.lua tests -o utfTerminal
nvim -l tests/minit.lua tests -o utfTerminal -Xoutput --color
fi
}

Expand Down
33 changes: 33 additions & 0 deletions tests/functional/requests_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,39 @@ describe("requests", function()
assert.has_string(request_body_computed, '"variables":{"id":1}')
end)

it("runs GraphQL request method", function()
curl.stub({
["https://countries.trevorblades.com"] = {
body = h.load_fixture("fixtures/graphql_schema_body.txt"),
},
})

h.create_buf(
([[
GRAPHQL https://countries.trevorblades.com

query Person($id: ID) {
person(personID: $id) {
name
}
}

{
"id": 1
}
]]):to_table(true),
"test.http"
)

kulala.run()
wait_for_requests(1)

local request_body_computed = DB.data.current_request.body_computed

assert.has_string(request_body_computed, '"query":"query Person($id: ID) { person(personID: $id) { name } }')
assert.has_string(request_body_computed, '"variables":{"id":1}')
end)

it("runs API callbacks", function()
curl.stub({
["https://httpbin.org/simple"] = {
Expand Down