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:16:46 UTC

[GitHub] [apisix] shuaijinchao opened a new pull request #6343: feat(graphql): support http get and post json request

shuaijinchao opened a new pull request #6343:
URL: https://github.com/apache/apisix/pull/6343


   ### What this PR does / why we need it:
   FIX #6266
   
   ### Pre-submission checklist:
   * [x] Did you explain what problem does this PR solve? Or what new features have been added?
   * [ ] Have you added corresponding test cases?
   * [ ] Have you modified the corresponding document?
   * [x] Is this PR backward compatible? **If it is not backward compatible, please discuss on the [mailing list](https://github.com/apache/apisix/tree/master#community) first**
   


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



[GitHub] [apisix] spacewander merged pull request #6343: feat(graphql): support http get and post json request

Posted by GitBox <gi...@apache.org>.
spacewander merged pull request #6343:
URL: https://github.com/apache/apisix/pull/6343


   


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



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

Posted by GitBox <gi...@apache.org>.
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



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

Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on a change in pull request #6343:
URL: https://github.com/apache/apisix/pull/6343#discussion_r807785879



##########
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]

Review comment:
       if it is a table, do you think should we use the first value in the table or reject the request.




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



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

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #6343:
URL: https://github.com/apache/apisix/pull/6343#discussion_r807879878



##########
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]

Review comment:
       We can use the first one




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



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

Posted by GitBox <gi...@apache.org>.
spacewander commented on a change in pull request #6343:
URL: https://github.com/apache/apisix/pull/6343#discussion_r807772718



##########
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]

Review comment:
       The body here might be a table

##########
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:
       We can pass ctx here?




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



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

Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on a change in pull request #6343:
URL: https://github.com/apache/apisix/pull/6343#discussion_r807901738



##########
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]

Review comment:
       updated

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

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

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