GuoMonth commented on issue #10346:
URL: https://github.com/apache/apisix/issues/10346#issuecomment-1780315170

   # Test Case 1
   
   ## 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 created
   ~>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:          1
     Resource Version:    27913024655
     Self Link:           
/apis/apisix.apache.org/v2/namespaces/xxxx-services/apisixroutes/fx-client-route
     UID:                 b75529cd-ed8c-4036-xxxx-3660775fxxxx
   Spec:
     Http:
       Backends:
         Service Name:  xxxx-fx-service-client-service
         Service Port:  8007
       Match:
         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:  1
       Reason:               ResourcesSynced
       Status:               True
       Type:                 ResourcesAvailable
   Events:
     Type    Reason           Age              From           Message
     ----    ------           ----             ----           -------
     Normal  ResourcesSynced  6s (x2 over 6s)  ApisixIngress  ApisixIngress 
synced successfully
   ```
   
   ## apisix-test.yaml content
   
   ```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
         backends:
           - serviceName: xxxx-fx-service-client-service
             servicePort: 8007
         plugins:
           - name: jwt-auth
             enable: true
           - name: cors
             enable: true
   
   ```
   
   ## Test
   
   1 cURL: success!
   
   ```
    ~> curl --location 'http://1.xx.xx.45:8082/client/graphql' \
   --header 'Content-Type: application/json' \
   --header 'Authorization: Bearer 
xxxbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTgzNzI1MjcsImtleSI6InVzZXIta2V5In0.JN126xataNmTw7-PgxxxvCwYClRSttob-xxxCerlRs'
 \
   --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": success!
   
   ```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;
           }
   ```
   


-- 
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]

Reply via email to