You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/03/04 03:03:12 UTC
[apisix] branch master updated: docs: add latest content about GraphQL in APISIX (#6449)
This is an automated email from the ASF dual-hosted git repository.
spacewander 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 66a5a2a docs: add latest content about GraphQL in APISIX (#6449)
66a5a2a is described below
commit 66a5a2a44a9a2ec1d9df63904ac50b9d73e4f79f
Author: John Chever <ch...@gmail.com>
AuthorDate: Fri Mar 4 11:02:58 2022 +0800
docs: add latest content about GraphQL in APISIX (#6449)
Co-authored-by: 琚致远 <ju...@apache.org>
---
docs/en/latest/router-radixtree.md | 38 +++++++++++++++++++++++++++++++++++---
docs/zh/latest/router-radixtree.md | 36 ++++++++++++++++++++++++++++++++++--
2 files changed, 69 insertions(+), 5 deletions(-)
diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md
index adaa0fe..e2d0de6 100644
--- a/docs/en/latest/router-radixtree.md
+++ b/docs/en/latest/router-radixtree.md
@@ -227,7 +227,7 @@ We can define the following route:
```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
- "methods": ["POST"],
+ "methods": ["POST", "GET"],
"uri": "/_post",
"vars": [
["post_arg_name", "==", "json"]
@@ -245,6 +245,8 @@ The route will be matched when the POST form contains `name=json`.
### How to filter route by GraphQL attributes
+APISIX can handle HTTP GET and POST methods. At the same time, the request body can be a GraphQL query string or JSON-formatted content.
+
APISIX supports filtering route by some attributes of GraphQL. Currently we support:
* graphql_operation
@@ -273,8 +275,8 @@ We can filter such route out with:
```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
- "methods": ["POST"],
- "uri": "/_graphql",
+ "methods": ["POST", "GET"],
+ "uri": "/graphql",
"vars": [
["graphql_operation", "==", "query"],
["graphql_name", "==", "getRepo"],
@@ -289,6 +291,36 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f
}'
```
+We can verify GraphQL matches in the following three ways:
+
+1. GraphQL query strings
+
+```shell
+$ curl -H 'content-type: application/graphql' -X POST http://127.0.0.1:9080/graphql -d '
+query getRepo {
+ owner {
+ name
+ }
+ repo {
+ created
+ }
+}'
+```
+
+2. JSON format
+
+```shell
+$ curl -H 'content-type: application/json' -X POST \
+http://127.0.0.1:9080/graphql --data '{"query": "query getRepo { owner {name } repo {created}}"}'
+```
+
+3. Try `GET` request match
+
+```shell
+$ curl -H 'content-type: application/graphql' -X GET \
+"http://127.0.0.1:9080/graphql?query=query getRepo { owner {name } repo {created}}" -g
+```
+
To prevent spending too much time reading invalid GraphQL request body, we only read the first 1 MiB
data from the request body. This limitation is configured via:
diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md
index 546258f..14bd0fb 100644
--- a/docs/zh/latest/router-radixtree.md
+++ b/docs/zh/latest/router-radixtree.md
@@ -246,6 +246,8 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f
### 如何通过 GraphQL 属性过滤路由
+目前,APISIX 可以处理 HTTP GET 和 POST 方法。请求体正文可以是 GraphQL 查询字符串,也可以是 JSON 格式的内容。
+
APISIX 支持通过 GraphQL 的一些属性过滤路由。 目前我们支持:
* graphql_operation
@@ -274,8 +276,8 @@ query getRepo {
```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d '
{
- "methods": ["POST"],
- "uri": "/_graphql",
+ "methods": ["POST", "GET"],
+ "uri": "/graphql",
"vars": [
["graphql_operation", "==", "query"],
["graphql_name", "==", "getRepo"],
@@ -290,6 +292,36 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f
}'
```
+我们可以通过以下三种方式分别去验证 GraphQL 匹配:
+
+1. 使用 GraphQL 查询字符串
+
+```shell
+$ curl -H 'content-type: application/graphql' -X POST http://127.0.0.1:9080/graphql -d '
+query getRepo {
+ owner {
+ name
+ }
+ repo {
+ created
+ }
+}'
+```
+
+2. 使用 JSON 格式
+
+```shell
+$ curl -H 'content-type: application/json' -X POST \
+http://127.0.0.1:9080/graphql --data '{"query": "query getRepo { owner {name } repo {created}}"}'
+```
+
+3. 尝试 `GET` 请求
+
+```shell
+$ curl -H 'content-type: application/graphql' -X GET \
+"http://127.0.0.1:9080/graphql?query=query getRepo { owner {name } repo {created}}" -g
+```
+
为了防止花费太多时间读取无效的 `GraphQL` 请求正文,我们只读取前 `1 MiB`
来自请求体的数据。 此限制是通过以下方式配置的: