From c3e2919b2ab2524b67c2221f0edfb3683353bb4d Mon Sep 17 00:00:00 2001 From: junbo dai Date: Fri, 1 Mar 2024 09:14:48 +0800 Subject: [PATCH] ADM-677[docs]feat: add curl for api (#1100) --- ...-api-about-replacing-existing-rest-api.mdx | 79 ++++++++++++++++++- 1 file changed, 76 insertions(+), 3 deletions(-) diff --git a/docs/src/content/docs/en/spikes/tech-spikes-github-graphql-api-about-replacing-existing-rest-api.mdx b/docs/src/content/docs/en/spikes/tech-spikes-github-graphql-api-about-replacing-existing-rest-api.mdx index 45a56adfae..19d44c3eb3 100644 --- a/docs/src/content/docs/en/spikes/tech-spikes-github-graphql-api-about-replacing-existing-rest-api.mdx +++ b/docs/src/content/docs/en/spikes/tech-spikes-github-graphql-api-about-replacing-existing-rest-api.mdx @@ -56,9 +56,19 @@ query { | 200 | Verification passed | | 401 | Verification failed | +##### 3.1.3 Test GraphQL API curl + +``` +curl --request POST \ + --url https://api.github.com/graphql \ + --header 'Authorization: token ghp_***...***' \ + --header 'content-type: application/json' \ + --data '{"query": "{viewer {login}}"}' +``` + #### 3.2. Verify the GitHub branch -##### 3.1.1 Replaced API and Method local +##### 3.2.1 Replaced API and Method local - Replaced api @@ -72,7 +82,7 @@ GET:https://api.github.com/repos/{repository}/branches/{branchName} GitHubFeignClient.verifyCanReadTargetBranch ``` -##### 3.1.2 API replaced by +##### 3.2.2 API replaced by ``` query { @@ -156,6 +166,17 @@ response: } ``` +##### 3.2.3 Test GraphQL API curl + +``` +curl --request POST \ + --url https://api.github.com/graphql \ + --header 'Authorization: token ghp_***...***' \ + --header 'content-type: application/json' \ + --data '{ + "query": "{repository(owner: \"au-heartbeat\", name: \"Heartbeat\") { ref(qualifiedName: \"refs/heads/main\") { name }}}" +}' +``` #### 3.3. Get commit info by commit id @@ -207,6 +228,8 @@ query { | name | repo | Heartbeat | | oid | commit id | 414e*********************************ae6 | +The value of `first` must be between 1 and 100. + if you want to get target commit for `au-heartbeat/Heartbeat`, you can use as following. ``` @@ -231,6 +254,17 @@ query { } ``` +##### 3.3.3 Test GraphQL API curl + +``` +curl --request POST \ + --url https://api.github.com/graphql \ + --header 'Authorization: token ghp_***...***' \ + --header 'Content-Type: application/json' \ + --header 'User-Agent: insomnia/8.6.0' \ + --data '{"query":"{ repository (owner: \"au-heartbeat\", name: \"Heartbeat\") { commit: object(oid: \"414e*********************************ae6\") { ... on Commit { message author { name email date } committer { name email date }}}}}"}' +``` + #### 3.4. Get commit info list by pull request ##### 3.4.1 Replaced API and Method local @@ -293,8 +327,21 @@ query { | first | per page num | 100 | | after | endCursor | MQ | +The value of `first` must be between 1 and 100. + You can put `endCursor` in `after` to get next page. +##### 3.4.3 Test GraphQL API curl + +``` +curl --request POST \ + --url https://api.github.com/graphql \ + --header 'Authorization: token ghp_***...***' \ + --header 'Content-Type: application/json' \ + --header 'User-Agent: insomnia/8.6.1' \ + --data '{"query":"{ repository(owner: \"au-heartbeat\", name: \"Heartbeat\") { pullRequest(number: 1037) { commits(first: 100, after: \"\") { edges { node { commit { oid message author { name email date } committer { name email date }}}} pageInfo { endCursor hasNextPage }}}}}"}' +``` + #### 3.5. Get pull request list info ##### 3.5.1 Replaced API and Method local @@ -350,8 +397,21 @@ query { | first | per page num | 100 | | after | endCursor | MQ | +The value of `first` must be between 1 and 100. + You can put `endCursor` in `after` to get next page. +##### 3.5.3 Test GraphQL API curl + +``` +curl --request POST \ + --url https://api.github.com/graphql \ + --header 'Authorization: token ghp_***...***' \ + --header 'Content-Type: application/json' \ + --header 'User-Agent: insomnia/8.6.0' \ + --data '{"query":"{ repository (owner: \"au-heartbeat\", name: \"Heartbeat\") { commit: object(oid: \"414e*********************************ae6\") { ... on Commit { associatedPullRequests(first: 100, after: \"\") { nodes { number createdAt mergedAt mergeCommit { oid }} pageInfo { endCursor hasNextPage }}}}}}"}' +``` + ### 4、How to call GraphQL in code - Call api by curl @@ -363,7 +423,7 @@ curl --request POST \ --url https://api.github.com/graphql \ --header 'Authorization: token ghp_***...***' \ --header 'content-type: application/json' \ - --data '{"query": "query {viewer {login}}"}' + --data '{"query": "{viewer {login}}"}' ``` ### 5、Api merge @@ -432,4 +492,17 @@ query { | first | per page num | 100 | | after | endCursor | MQ | +The value of `first` must be between 1 and 100. + You can put `endCursor` in `after` to get next page. + +- Test GraphQL API curl + +``` +curl --request POST \ + --url https://api.github.com/graphql \ + --header 'Authorization: token ghp_***...***' \ + --header 'Content-Type: application/json' \ + --header 'User-Agent: insomnia/8.6.1' \ + --data '{"query":"{ repository(owner: \"au-heartbeat\", name: \"Heartbeat\") { object(expression: \"414e*********************************ae6\") { ... on Commit { associatedPullRequests(first: 100, after: \"\") { edges { node { number createdAt mergedAt mergeCommit { oid } commits(first: 100, after: \"\") { edges { node { commit { oid message author { name email date } committer { name email date }}}} pageInfo { endCursor hasNextPage }}}} pageInfo { endCursor hasNextPage }}}}}}"}' +```