Skip to content

Commit

Permalink
fix: the _graphql was incorrectly cached under ctx.var but not ctx (#…
Browse files Browse the repository at this point in the history
…4723)

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander authored Aug 1, 2021
1 parent e4f0491 commit 38561dc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
5 changes: 3 additions & 2 deletions apisix/core/ctx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ local function parse_graphql(ctx)
end


local function get_parsed_graphql(ctx)
local function get_parsed_graphql()
local ctx = ngx.ctx.api_ctx
if ctx._graphql then
return ctx._graphql
end
Expand Down Expand Up @@ -171,7 +172,7 @@ do
elseif core_str.has_prefix(key, "graphql_") then
-- trim the "graphql_" prefix
key = sub_str(key, 9)
val = get_parsed_graphql(t)[key]
val = get_parsed_graphql()[key]

elseif key == "route_id" then
val = ngx.ctx.api_ctx and ngx.ctx.api_ctx.route_id
Expand Down
52 changes: 52 additions & 0 deletions t/core/ctx2.t
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,55 @@ qr/balancer_ip: 127.0.0.1|balancer_port: 1980/
--- grep_error_log_out
balancer_ip: 127.0.0.1
balancer_port: 1980
=== TEST 5: parsed graphql is cached under ctx
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[=[{
"methods": ["POST"],
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"plugins": {
"serverless-pre-function": {
"phase": "header_filter",
"functions" : ["return function(conf, ctx) ngx.log(ngx.WARN, 'find ctx._graphql: ', ctx._graphql ~= nil) end"]
}
},
"uri": "/hello",
"vars": [["graphql_name", "==", "repo"]]
}]=]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed
=== TEST 6: hit
--- request
POST /hello
query repo {
owner {
name
}
}
--- response_body
hello world
--- error_log
find ctx._graphql: true

0 comments on commit 38561dc

Please sign in to comment.