This is an automated email from the ASF dual-hosted git repository.

tokers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 38561dc  fix: the _graphql was incorrectly cached under ctx.var but 
not ctx (#4723)
38561dc is described below

commit 38561dc0cd13ee412d05a96153dee80018f1e799
Author: 罗泽轩 <[email protected]>
AuthorDate: Sun Aug 1 19:26:27 2021 +0800

    fix: the _graphql was incorrectly cached under ctx.var but not ctx (#4723)
    
    Signed-off-by: spacewander <[email protected]>
---
 apisix/core/ctx.lua |  5 +++--
 t/core/ctx2.t       | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/apisix/core/ctx.lua b/apisix/core/ctx.lua
index aabf8a5..aa52244 100644
--- a/apisix/core/ctx.lua
+++ b/apisix/core/ctx.lua
@@ -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
@@ -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
diff --git a/t/core/ctx2.t b/t/core/ctx2.t
index 70082d9..478f0a9 100644
--- a/t/core/ctx2.t
+++ b/t/core/ctx2.t
@@ -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

Reply via email to