diff --git a/docs/en/latest/router-radixtree.md b/docs/en/latest/router-radixtree.md index adaa0fe69a93..e2d0de65b6ff 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 546258f502af..14bd0fb00bbf 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` 来自请求体的数据。 此限制是通过以下方式配置的: