-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: ctx.lua#59 parse_graphql(ctx) #6266
Comments
maybe bad graphql, see: Lines 165 to 171 in ec0fc2c
|
@tzssangglass it's not a bad graphql
this request will route to backend, but backend will parse error |
try
? |
curl 'https://api.mocki.io/v2/c4d7a195/graphql' \
-H 'authority: api.mocki.io' \
-H 'accept: */*' \
-H 'content-type: application/json' \
-H 'origin: https://api.mocki.io' \
--data-raw '{"operationName":"getUser","variables":{},"query":"query getUser {\n user(id: \"4dc70521-22bb-4396-b37a-4a927c66d43b\") {\n id\n email\n name\n }\n}\n"}' \
--compressed 会返回 {
"data": {
"user": {
"id": "Hello World",
"email": "Hello World",
"name": "Hello World"
}
}
}
### 添加测试的graphql请求
curl http://localhost:9080/apisix/admin/routes/7 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
"methods": ["POST"],
"name":"mockGetUser",
"uri": "/v2/c4d7a195/graphql",
"vars": [
["graphql_operation", "==", "query"],
["graphql_name", "==", "getUser"]
],
"upstream": {
"type": "roundrobin",
"nodes": {
"api.mocki.io": 1
}
}
}'
### apisix graphql
curl 'https://localhost:9080/v2/c4d7a195/graphql' \
-H 'authority: api.mocki.io' \
-H 'accept: */*' \
-H 'content-type: application/json' \
-H 'origin: https://api.mocki.io' \
--data-raw '{"operationName":"getUser","variables":{},"query":"query getUser {\n user(id: \"4dc70521-22bb-4396-b37a-4a927c66d43b\") {\n id\n email\n name\n }\n}\n"}' \
--compressed 会返回 {
"error_msg": "404 Route Not Found"
} 错误日志是 |
@pcyan The route method has been set to |
As stated above, this should be a must |
In fact, I tested both commands locally and they worked config
curl command
It could be that you missed '-POST'? |
A standard GraphQL POST request should use the application/json content type, and include a JSON-encoded body of the following form: {
"query": "...",
"operationName": "...",
"variables": { "myVariable": "someValue", ... }
} see official graphql document, https://graphql.org/learn/serving-over-http/#post-request and |
Where is it? I'm wondering where the error is caused by missing |
I could not find the relevant description in the Suggest like this:
|
$ curl --help
Usage: curl [options...] <url>
-d, --data <data> **HTTP POST data**
...
use curl -v 'https://api.mocki.io/v2/c4d7a195/graphql' \
-H 'authority: api.mocki.io' \
-H 'accept: */*' \
-H 'content-type: application/json' \
-H 'origin: https://api.mocki.io' \
--data-raw '{"operationName":"getUser","variables":{},"query":"query getUser {\n user(id: \"4dc70521-22bb-4396-b37a-4a927c66d43b\") {\n id\n email\n name\n }\n}\n"}' \
--compressed it will print something like this sorry, i'm try to discuss about how APISIX deal with graphql request. it seems that the mock GraphQL data of APISIX is not a standard GraphQL request. |
Oh, I see, the error caused by graphql/parse.lua, it seems the graphql can't process a standard GraphQL request. |
After discussion and review, it was found that the cause of this issue was that we did not support the application/json content type. I will mainly solve this issue in the next 3 days. @pcyan |
@Chever-John May I also suggest that the
|
In fact, these are the two new features (support 'json' & 'GET') that we're going to release next.
|
Issue description
use whole request body to parse graphql will get parse error.
graphql request body is json , example :
{"query":"query{getUser{name age}}","variables":null}
, notquery{getUser{name age}}
Environment
apisix version
):apache/apisix:2.12.0-alpine
uname -a
):docker
nginx -V
oropenresty -V
): nullcurl http://127.0.0.1:9090/v1/server_info
to get the info from server-info API):bitnami/etcd:3.4.15
apache/apisix-dashboard:2.10.1-alpine
luarocks --version
):Steps to reproduce
Actual result
HTTP/1.1 404 Not Found
Date: Tue, 08 Feb 2022 07:39:16 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
{
"error_msg": "404 Route Not Found"
}
Error log
2022/02/08 07:39:16 [error] 45#45: *1085159 [lua] ctx.lua:80: get_parsed_graphql(): failed to parse graphql: Syntax error near line 1 body:
Expected result
success
The text was updated successfully, but these errors were encountered: