spacewander commented on a change in pull request #2964:
URL: https://github.com/apache/apisix/pull/2964#discussion_r538189387
##########
File path: apisix/core/ctx.lua
##########
@@ -15,22 +15,96 @@
-- limitations under the License.
--
local core_str = require("apisix.core.string")
+local core_tab = require("apisix.core.table")
+local request = require("apisix.core.request")
local log = require("apisix.core.log")
+local config_local = require("apisix.core.config_local")
local tablepool = require("tablepool")
local get_var = require("resty.ngxvar").fetch
local get_request = require("resty.ngxvar").request
local ck = require "resty.cookie"
+local gq_parse = require("graphql").parse
local setmetatable = setmetatable
local sub_str = string.sub
local rawset = rawset
+local ngx = ngx
local ngx_var = ngx.var
local re_gsub = ngx.re.gsub
+local ipairs = ipairs
local type = type
local error = error
-local ngx = ngx
+local pcall = pcall
local _M = {version = 0.2}
+local GRAPHQL_DEFAULT_MAX_SIZE = 1048576 -- 1MiB
+
+
+local function parse_graphql(ctx)
+ local local_conf, err = config_local.local_conf()
+ if not local_conf then
+ return nil, "failed to get local conf: " .. err
+ end
+
+ local max_size = GRAPHQL_DEFAULT_MAX_SIZE
+ local size = core_tab.try_read_attr(local_conf, "graphql", "max_size")
+ if size then
+ max_size = size
+ end
+
+ local body, err = request.get_body(max_size, ctx)
+ if not body then
+ return nil, "failed to read graphql body: " .. err
+ end
+
+ local ok, res = pcall(gq_parse, body)
+ if not ok then
+ return nil, "failed to parse graphql: " .. res .. " body: " .. body
+ end
+
+ if #res.definitions == 0 then
+ return nil, "empty graphql: " .. body
+ end
+
+ return res
+end
+
+
+local function get_parsed_graphql(ctx)
+ if not ctx._graphql then
Review comment:
updated
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]