You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/02/16 10:39:48 UTC

[GitHub] [apisix] shuaijinchao commented on a change in pull request #6343: feat(graphql): support http get and post json request

shuaijinchao commented on a change in pull request #6343:
URL: https://github.com/apache/apisix/pull/6343#discussion_r807783678



##########
File path: apisix/core/ctx.lua
##########
@@ -36,7 +37,48 @@ local pcall        = pcall
 
 
 local _M = {version = 0.2}
-local GRAPHQL_DEFAULT_MAX_SIZE = 1048576               -- 1MiB
+local GRAPHQL_DEFAULT_MAX_SIZE       = 1048576               -- 1MiB
+local GRAPHQL_REQ_DATA_KEY           = "query"
+local GRAPHQL_REQ_METHOD_HTTP_GET    = "GET"
+local GRAPHQL_REQ_METHOD_HTTP_POST   = "POST"
+local GRAPHQL_REQ_MIME_JSON          = "application/json"
+
+
+local fetch_graphql_data = {
+    [GRAPHQL_REQ_METHOD_HTTP_GET] = function(ctx, max_size)
+        local body = request.get_uri_args(ctx)[GRAPHQL_REQ_DATA_KEY]
+        if not body then
+            return nil, "failed to read graphql data, args[ " ..
+                        GRAPHQL_REQ_DATA_KEY .. "] is nil"
+        end
+
+        return body
+    end,
+
+    [GRAPHQL_REQ_METHOD_HTTP_POST] = function(ctx, max_size)
+        local body, err = request.get_body(max_size, ctx)
+        if not body then
+            return nil, "failed to read graphql data, " .. (err or "request body has zero size")
+        end
+
+        if request.header(nil, "Content-Type") == GRAPHQL_REQ_MIME_JSON then

Review comment:
       Of course, I update it later.




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org