From e21b3cad6871c8089ecb76fecb29ac7e0a0ff5f8 Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Fri, 25 Feb 2022 15:55:13 +0800 Subject: [PATCH 01/16] docs: add latest content about GraphQL in APISIX --- docs/zh/latest/router-radixtree.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md index 546258f502af..1e00bb84a5d2 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 @@ -290,6 +292,24 @@ $ 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}}"}' + ``` + 为了防止花费太多时间读取无效的 `GraphQL` 请求正文,我们只读取前 `1 MiB` 来自请求体的数据。 此限制是通过以下方式配置的: From 316d6defe428e4b79f8ec91eafeb4d0439e98145 Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Fri, 25 Feb 2022 15:59:11 +0800 Subject: [PATCH 02/16] docs: add english version --- docs/en/latest/router-radixtree.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index adaa0fe69a93..07a0a81cd4c4 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -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 @@ -289,6 +291,24 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f }' ``` +We can verify GraphQL matches in the following two ways: +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}}"}' + ``` + 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: From 3e46bdfc6573be087854ccac68024a17b0e6051f Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Fri, 25 Feb 2022 16:03:28 +0800 Subject: [PATCH 03/16] docs: solve ci error --- docs/en/latest/router-radixtree.md | 1 + docs/zh/latest/router-radixtree.md | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index 07a0a81cd4c4..2fe14e7c6354 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -292,6 +292,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f ``` We can verify GraphQL matches in the following two ways: + 1. 使用 GraphQL 查询字符串 ```shell $ curl -H 'content-type: application/graphql' -X POST http://127.0.0.1:9080/graphql -d ' diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md index 1e00bb84a5d2..01713a12d194 100644 --- a/docs/zh/latest/router-radixtree.md +++ b/docs/zh/latest/router-radixtree.md @@ -293,6 +293,7 @@ $ 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 ' From 76c67534c60249adef8483eedb71dd88c0605e71 Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Fri, 25 Feb 2022 16:04:48 +0800 Subject: [PATCH 04/16] docs: solve ci error 2 --- docs/en/latest/router-radixtree.md | 2 ++ docs/zh/latest/router-radixtree.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index 2fe14e7c6354..189c492b2171 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -294,6 +294,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f We can verify GraphQL matches in the following two ways: 1. 使用 GraphQL 查询字符串 + ```shell $ curl -H 'content-type: application/graphql' -X POST http://127.0.0.1:9080/graphql -d ' query getRepo { @@ -306,6 +307,7 @@ We can verify GraphQL matches in the following two ways: }' ``` 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}}"}' ``` diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md index 01713a12d194..390a7b2386ba 100644 --- a/docs/zh/latest/router-radixtree.md +++ b/docs/zh/latest/router-radixtree.md @@ -295,6 +295,7 @@ $ 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 { @@ -307,6 +308,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f }' ``` 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}}"}' ``` From b99b40e47dbd34d200a28d404fb384763e00c7cb Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Fri, 25 Feb 2022 16:10:42 +0800 Subject: [PATCH 05/16] docs: solve ci error3 --- docs/en/latest/router-radixtree.md | 1 + docs/zh/latest/router-radixtree.md | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index 189c492b2171..26263c0648ba 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -306,6 +306,7 @@ We can verify GraphQL matches in the following two ways: } }' ``` + 2. 使用 JSON 格式 ```shell diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md index 390a7b2386ba..2acb6316ef51 100644 --- a/docs/zh/latest/router-radixtree.md +++ b/docs/zh/latest/router-radixtree.md @@ -307,6 +307,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f } }' ``` + 2. 使用 JSON 格式 ```shell From bd0e09426e2b5549d2bbb05929c2069c64c9c278 Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Fri, 25 Feb 2022 16:25:42 +0800 Subject: [PATCH 06/16] docs: all english --- docs/en/latest/router-radixtree.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index 26263c0648ba..783528d4b0e2 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -293,7 +293,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f We can verify GraphQL matches in the following two ways: -1. 使用 GraphQL 查询字符串 +1. GraphQL query strings ```shell $ curl -H 'content-type: application/graphql' -X POST http://127.0.0.1:9080/graphql -d ' @@ -307,7 +307,7 @@ We can verify GraphQL matches in the following two ways: }' ``` -2. 使用 JSON 格式 +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}}"}' From 23a71cd83b8654b0b3a7e464d86919f2f5649c56 Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Fri, 25 Feb 2022 17:09:29 +0800 Subject: [PATCH 07/16] test --- docs/en/latest/router-radixtree.md | 2 +- docs/zh/latest/router-radixtree.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index 783528d4b0e2..068596dfb860 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -306,7 +306,7 @@ We can verify GraphQL matches in the following two ways: } }' ``` - + 2. JSON format ```shell diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md index 2acb6316ef51..39417e7d03c1 100644 --- a/docs/zh/latest/router-radixtree.md +++ b/docs/zh/latest/router-radixtree.md @@ -307,7 +307,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f } }' ``` - + 2. 使用 JSON 格式 ```shell From 0f349d0a04b0c8eeaf6ffacb8bc792217ac80cdd Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Fri, 25 Feb 2022 17:34:08 +0800 Subject: [PATCH 08/16] docs: add GET in document --- docs/en/latest/router-radixtree.md | 28 ++++++++++++++++++++++++++++ docs/zh/latest/router-radixtree.md | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index 068596dfb860..197f666fc415 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -313,6 +313,34 @@ We can verify GraphQL matches in the following two ways: $ curl -H 'content-type: application/json' -X POST http://127.0.0.1:9080/graphql --data '{"query": "query getRepo { owner {name } repo {created}}"}' ``` +Next, try a GET request. +Let's first configure a route like this: + +```shell +$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +{ + "methods": ["GET"], + "uri": "/_graphql", + "vars": [ + ["graphql_operation", "==", "query"], + ["graphql_name", "==", "getRepo"], + ["graphql_root_fields", "has", "owner"] + ], + "upstream": { + "type": "roundrobin", + "nodes": { + "39.97.63.215:4000": 1 + } + } +}' +``` + +We can verify GraphQL matches in the following way: + +```shell +curl -H 'content-type: application/graphql' -X GET "http://127.0.0.1:9080/graphql?query=query getRepo { owner {name } repo {created}}" -g +``` +H 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 39417e7d03c1..1bb935ad1c1a 100644 --- a/docs/zh/latest/router-radixtree.md +++ b/docs/zh/latest/router-radixtree.md @@ -314,6 +314,34 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f $ curl -H 'content-type: application/json' -X POST http://127.0.0.1:9080/graphql --data '{"query": "query getRepo { owner {name } repo {created}}"}' ``` +接下来,尝试一下 GET 请求。 +我们首先配置这样的路由: + +```shell +$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' +{ + "methods": ["GET"], + "uri": "/_graphql", + "vars": [ + ["graphql_operation", "==", "query"], + ["graphql_name", "==", "getRepo"], + ["graphql_root_fields", "has", "owner"] + ], + "upstream": { + "type": "roundrobin", + "nodes": { + "39.97.63.215:4000": 1 + } + } +}' +``` + +我们可以通过以下方式去验证 GraphQL 匹配: + +```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` 来自请求体的数据。 此限制是通过以下方式配置的: From d084301120b8305d1d4c115e6cdabe44afb8999f Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Fri, 25 Feb 2022 17:45:14 +0800 Subject: [PATCH 09/16] docs: del indentation & keep it consistent --- docs/en/latest/router-radixtree.md | 28 ++++++++++++++-------------- docs/zh/latest/router-radixtree.md | 28 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index 197f666fc415..3f5d1efe1c8c 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -295,23 +295,23 @@ We can verify GraphQL matches in the following two 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 - } - }' - ``` +```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}}"}' - ``` +```shell +$ curl -H 'content-type: application/json' -X POST http://127.0.0.1:9080/graphql --data '{"query": "query getRepo { owner {name } repo {created}}"}' +``` Next, try a GET request. Let's first configure a route like this: diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md index 1bb935ad1c1a..c7b3e3386d6c 100644 --- a/docs/zh/latest/router-radixtree.md +++ b/docs/zh/latest/router-radixtree.md @@ -296,23 +296,23 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f 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 - } - }' - ``` +```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}}"}' - ``` +```shell +$ curl -H 'content-type: application/json' -X POST http://127.0.0.1:9080/graphql --data '{"query": "query getRepo { owner {name } repo {created}}"}' +``` 接下来,尝试一下 GET 请求。 我们首先配置这样的路由: From 576bba76084a1506e06cc3d991608960226cb66a Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Fri, 25 Feb 2022 18:04:18 +0800 Subject: [PATCH 10/16] test --- docs/en/latest/router-radixtree.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index 3f5d1efe1c8c..4e35c54cb3fe 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -340,7 +340,7 @@ We can verify GraphQL matches in the following way: ```shell curl -H 'content-type: application/graphql' -X GET "http://127.0.0.1:9080/graphql?query=query getRepo { owner {name } repo {created}}" -g ``` -H + 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: From 91d89c871d3a342ef0c4edd701aae060a5ab11ed Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Mon, 28 Feb 2022 09:41:12 +0800 Subject: [PATCH 11/16] docs: Refactor the GET and POST requests --- docs/en/latest/router-radixtree.md | 28 +++------------------------- docs/zh/latest/router-radixtree.md | 26 ++------------------------ 2 files changed, 5 insertions(+), 49 deletions(-) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index 4e35c54cb3fe..0558c6630300 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"] @@ -275,7 +275,7 @@ 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"], + "methods": ["POST", "GET"], "uri": "/_graphql", "vars": [ ["graphql_operation", "==", "query"], @@ -313,29 +313,7 @@ query getRepo { $ curl -H 'content-type: application/json' -X POST http://127.0.0.1:9080/graphql --data '{"query": "query getRepo { owner {name } repo {created}}"}' ``` -Next, try a GET request. -Let's first configure a route like this: - -```shell -$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' -{ - "methods": ["GET"], - "uri": "/_graphql", - "vars": [ - ["graphql_operation", "==", "query"], - ["graphql_name", "==", "getRepo"], - ["graphql_root_fields", "has", "owner"] - ], - "upstream": { - "type": "roundrobin", - "nodes": { - "39.97.63.215:4000": 1 - } - } -}' -``` - -We can verify GraphQL matches in the following way: +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 diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md index c7b3e3386d6c..d57072e79923 100644 --- a/docs/zh/latest/router-radixtree.md +++ b/docs/zh/latest/router-radixtree.md @@ -276,7 +276,7 @@ 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"], + "methods": ["POST", "GET"], "uri": "/_graphql", "vars": [ ["graphql_operation", "==", "query"], @@ -314,29 +314,7 @@ query getRepo { $ curl -H 'content-type: application/json' -X POST http://127.0.0.1:9080/graphql --data '{"query": "query getRepo { owner {name } repo {created}}"}' ``` -接下来,尝试一下 GET 请求。 -我们首先配置这样的路由: - -```shell -$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' -{ - "methods": ["GET"], - "uri": "/_graphql", - "vars": [ - ["graphql_operation", "==", "query"], - ["graphql_name", "==", "getRepo"], - ["graphql_root_fields", "has", "owner"] - ], - "upstream": { - "type": "roundrobin", - "nodes": { - "39.97.63.215:4000": 1 - } - } -}' -``` - -我们可以通过以下方式去验证 GraphQL 匹配: +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 From 77e4637460926e1e1416220778c2f6e16ca895e1 Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Tue, 1 Mar 2022 13:27:57 +0800 Subject: [PATCH 12/16] docs: fix small error --- docs/en/latest/router-radixtree.md | 2 +- docs/zh/latest/router-radixtree.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index 0558c6630300..37bda18524e2 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -313,7 +313,7 @@ query getRepo { $ 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 +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 diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md index d57072e79923..48f6be7655f6 100644 --- a/docs/zh/latest/router-radixtree.md +++ b/docs/zh/latest/router-radixtree.md @@ -314,7 +314,7 @@ query getRepo { $ 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 请求 +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 From 327777c438fb7f73d340dfa5ab98af12056a4fc3 Mon Sep 17 00:00:00 2001 From: John Chever Date: Wed, 2 Mar 2022 16:46:55 +0800 Subject: [PATCH 13/16] Update docs/zh/latest/router-radixtree.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 琚致远 --- docs/zh/latest/router-radixtree.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md index 48f6be7655f6..89b6f10fe706 100644 --- a/docs/zh/latest/router-radixtree.md +++ b/docs/zh/latest/router-radixtree.md @@ -246,7 +246,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f ### 如何通过 GraphQL 属性过滤路由 -目前为止,APISIX 可以处理 HTTP GET 和 POST 方法。同时请求体正文可以是 GraphQL 查询字符串,也可以是 JSON 格式的内容。 +目前,APISIX 可以处理 HTTP GET 和 POST 方法。请求体正文可以是 GraphQL 查询字符串,也可以是 JSON 格式的内容。 APISIX 支持通过 GraphQL 的一些属性过滤路由。 目前我们支持: From fc4cb716e7fb5f6d5aae2b7dccc5109ecdd2863e Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Wed, 2 Mar 2022 21:23:38 +0800 Subject: [PATCH 14/16] docs: fix code example --- docs/en/latest/router-radixtree.md | 8 +++++--- docs/zh/latest/router-radixtree.md | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index 37bda18524e2..a2ade1ad881a 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -276,7 +276,7 @@ We can filter such route out with: $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' { "methods": ["POST", "GET"], - "uri": "/_graphql", + "uri": "/graphql", "vars": [ ["graphql_operation", "==", "query"], ["graphql_name", "==", "getRepo"], @@ -310,13 +310,15 @@ query getRepo { 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}}"}' +$ 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 +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 diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md index 89b6f10fe706..2c7f9bd63296 100644 --- a/docs/zh/latest/router-radixtree.md +++ b/docs/zh/latest/router-radixtree.md @@ -277,7 +277,7 @@ query getRepo { $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -i -d ' { "methods": ["POST", "GET"], - "uri": "/_graphql", + "uri": "/graphql", "vars": [ ["graphql_operation", "==", "query"], ["graphql_name", "==", "getRepo"], @@ -311,13 +311,15 @@ query getRepo { 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}}"}' +$ 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 +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` From 01eccf4b2da0df99a6fb64587e11b5d1f1f47667 Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Thu, 3 Mar 2022 10:35:21 +0800 Subject: [PATCH 15/16] docs: Uniform symbol --- docs/en/latest/router-radixtree.md | 2 +- docs/zh/latest/router-radixtree.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index a2ade1ad881a..2c2dcdd45c36 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -317,7 +317,7 @@ http://127.0.0.1:9080/graphql --data '{"query": "query getRepo { owner {name } r 3. Try `GET` request match ```shell -curl -H 'content-type: application/graphql' -X GET \ +$ curl -H 'content-type: application/graphql' -X GET \ "http://127.0.0.1:9080/graphql?query=query getRepo { owner {name } repo {created}}" -g ``` diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md index 2c7f9bd63296..820c938db13d 100644 --- a/docs/zh/latest/router-radixtree.md +++ b/docs/zh/latest/router-radixtree.md @@ -318,7 +318,7 @@ http://127.0.0.1:9080/graphql --data '{"query": "query getRepo { owner {name } r 3. 尝试 `GET` 请求 ```shell -curl -H 'content-type: application/graphql' -X GET \ +$ curl -H 'content-type: application/graphql' -X GET \ "http://127.0.0.1:9080/graphql?query=query getRepo { owner {name } repo {created}}" -g ``` From d533e25b6db08201183dc3f1c9c81a98f5aeaf97 Mon Sep 17 00:00:00 2001 From: cheverjohn Date: Thu, 3 Mar 2022 10:48:27 +0800 Subject: [PATCH 16/16] docs: fix small error --- docs/en/latest/router-radixtree.md | 2 +- docs/zh/latest/router-radixtree.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index 2c2dcdd45c36..e2d0de65b6ff 100644 --- a/docs/en/latest/router-radixtree.md +++ b/docs/en/latest/router-radixtree.md @@ -291,7 +291,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f }' ``` -We can verify GraphQL matches in the following two ways: +We can verify GraphQL matches in the following three ways: 1. GraphQL query strings diff --git a/docs/zh/latest/router-radixtree.md b/docs/zh/latest/router-radixtree.md index 820c938db13d..14bd0fb00bbf 100644 --- a/docs/zh/latest/router-radixtree.md +++ b/docs/zh/latest/router-radixtree.md @@ -292,7 +292,7 @@ $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f }' ``` -我们可以通过以下两种方式分别去验证 GraphQL 匹配: +我们可以通过以下三种方式分别去验证 GraphQL 匹配: 1. 使用 GraphQL 查询字符串