GuoMonth commented on issue #10346:
URL: https://github.com/apache/apisix/issues/10346#issuecomment-1780324950
# Test Case 2
## config the apisix route
```bash
~> kubectl apply -n xxxx-services -f
/Users/guosheng/AzureDevOps/fx-service-client/apisix-test.yaml
apisixroute.apisix.apache.org/fx-client-route configured
~> kubectl describe ApisixRoute -n xxxx-services fx-client-route
Name: fx-client-route
Namespace: xxxx-services
Labels: <none>
Annotations: <none>
API Version: apisix.apache.org/v2
Kind: ApisixRoute
Metadata:
Creation Timestamp: 2023-10-26T02:10:29Z
Generation: 2
Resource Version: 27913423206
Self Link:
/apis/apisix.apache.org/v2/namespaces/xxxx-services/apisixroutes/fx-client-route
UID: b75529cd-ed8c-4036-b855-3xxxx75fc67f
Spec:
Http:
Backends:
Service Name: xxxx-fx-service-client-service
Service Port: 8007
Match:
Exprs:
Op: Equal
Subject:
Name: graphql_operation
Scope: Variable
Value: query
Methods:
POST
GET
Paths:
/client/graphql
Name: fx-client-rule-graphql
Plugins:
Enable: true
Name: jwt-auth
Enable: true
Name: cors
Status:
Conditions:
Message: Sync Successfully
Observed Generation: 2
Reason: ResourcesSynced
Status: True
Type: ResourcesAvailable
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ResourcesSynced 11s (x4 over 18m) ApisixIngress ApisixIngress
synced successfully
```
## apisix-test.yaml
```yaml
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
name: fx-client-route
spec:
http:
- name: fx-client-rule-graphql
match:
methods: ["POST", "GET"]
paths:
- /client/graphql
exprs:
- subject:
scope: Variable
name: graphql_operation
op: Equal
value: query
backends:
- serviceName: xxxx-fx-service-client-service
servicePort: 8007
plugins:
- name: jwt-auth
enable: true
- name: cors
enable: true
```
## Test
1 cURL: success!
```bash
~> curl --location 'http://xx.xx.xx.xx:xxx/client/graphql' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer
eyJhxxxx1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOxxxgzNzI1MjcsImtleSI6InVzZxxxn0.JN126xataNmTw7-Pgj34vCwYCxxxttob-l2FYCerlRs'
\
--data '{"query":"query tClientInfo($pageSize: Int!, $pageIndex: Int!) {\n
tClientInfo(\n filters: { status: { eq: 1 } }\n pagination: {
page: { limit: $pageSize, page: $pageIndex } }\n orderBy: { updateTime:
DESC }\n ) {\n nodes {\n id\n clientId\n
clientCode\n clientName\n status\n
createUser\n createTime\n remark\n
updateTime\n updateUser\n }\n paginationInfo {\n
pages\n current\n }\n
}\n}\n","variables":{"pageSize":3,"pageIndex":1}}'
{"data":{"tClientInfo":{"nodes":[],"paginationInfo":{"pages":1,"current":1}}}}%
```
2 my .net 7 App, Include="GraphQL.Client" Version="6.0.0": failed!
```csharp
public async Task<PageData<ClientInfoData>> RetrieveByPage(int
index, int size)
{
GraphQLRequest fetchQuery = new()
{
Query = @"query tClientInfo($pageSize: Int!, $pageIndex:
Int!) {
tClientInfo(
filters: { status: { eq: 1 } }
pagination: { page: { limit: $pageSize, page:
$pageIndex } }
orderBy: { updateTime: DESC }
) {
nodes {
id
clientId
clientCode
clientName
status
createUser
createTime
remark
updateTime
updateUser
}
paginationInfo {
pages
current
}
}
}",
Variables = new
{
pageSize = size,
pageIndex = index,
},
};
var token = await
this.LocalStorage.GetItemAsync<string>("Token");
this.GraphqlHttp.HttpClient.DefaultRequestHeaders.Authorization
= new AuthenticationHeaderValue("Bearer", token);
var fetchResJson = await
this.GraphqlHttp.SendQueryAsync<JsonDocument>(fetchQuery);
var fetchResData =
fetchResJson.Data.RootElement.GetProperty("tClientInfo").GetProperty("nodes");
var fetchResPaginationInfo =
fetchResJson.Data.RootElement.GetProperty("tClientInfo").GetProperty("paginationInfo");
var totalPages =
fetchResPaginationInfo.GetProperty("pages").GetInt32();
var data = fetchResData.Deserialize<List<ClientInfoData>>() ??
new List<ClientInfoData>();
var clientInfoPage = new PageData<ClientInfoData>
{
Data = data,
TotalPages = totalPages,
PageIndex = index,
PageSize = size,
Total = totalPages * size, // note: this is not accurate,
because graphql not respond 'total' info.
};
return clientInfoPage;
}
```
apisix error log:
```text
172.17.0.6 - - [26/Oct/2023:02:34:07 +0000] xx.xx.xx.xx:xx "POST
/client/graphql HTTP/1.1" 404 47 0.000 "http://localhost:5003/" "Mozilla/5.0
(Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.61" - - - "http://xx.xx.xx.xx:xx"
2023/10/26 02:34:59 [error] 52#52: *669067163 [lua] ctx.lua:138:
get_parsed_graphql(): failed to parse graphql: Syntax error near line 1 body:
{"query":"query tClientInfo($pageSize: Int!, $pageIndex: Int!) {\n
tClientInfo(\n filters: { status: { eq: 1 } }\n
pagination: { page: { limit: $pageSize, page: $pageIndex }
}\n orderBy: { updateTime: DESC }\n )
{\n nodes {\n id\n
clientId\n clientCode\n
clientName\n status\n
createUser\n createTime\n
remark\n updateTime\n
updateUser\n }\n
paginationInfo {\n pages\n
current\n }\n }\n
}","variables":{"pageSize":15,"pageIndex":0}}, client: 172.17.0.6,
server: _, request: "POST /client/graphql HTTP/1.1", host: "xx.xx.xx.xx:xx",
referrer: "http://localhost:5003/"
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]