Skip to content

Commit 21e434d

Browse files
committed
fix: properly list all apps on a server
The previous method did not take pagination into account.
1 parent ea09360 commit 21e434d

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

main.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"log"
1010
"net/http"
1111
"os"
12+
"sort"
1213

1314
"github.com/akamensky/argparse"
1415
"github.com/machinebox/graphql"
@@ -56,12 +57,12 @@ func basicAuth(username, password string) string {
5657

5758
func appsList() {
5859
req := graphql.NewRequest(`
59-
query apps($allApps: Boolean) {
60-
apps(allApps: $allApps) {
61-
nextPage
60+
query apps($page: Int!, $allApps: Boolean!) {
61+
apps(page: $page, allApps: $allApps) {
6262
apps {
6363
name
6464
}
65+
nextPage
6566
}
6667
}
6768
`)
@@ -79,11 +80,31 @@ query apps($allApps: Boolean) {
7980
if err != nil {
8081
log.Fatal(err)
8182
}
82-
if err := client.Run(ctx, req, &respData); err != nil {
83-
log.Fatal(err)
83+
84+
var apps []string
85+
page := 1
86+
for true {
87+
if page == 0 {
88+
break
89+
}
90+
91+
req.Var("page", page)
92+
if err := client.Run(ctx, req, &respData); err != nil {
93+
log.Fatal(err)
94+
}
95+
for _, app := range respData.AppsWrapper.Apps {
96+
apps = append(apps, app.Name)
97+
}
98+
99+
if page == respData.AppsWrapper.NextPage {
100+
break
101+
}
102+
page = respData.AppsWrapper.NextPage
84103
}
85-
for _, app := range respData.AppsWrapper.Apps {
86-
fmt.Printf("%v\n", app.Name)
104+
105+
sort.Strings(apps)
106+
for _, app := range apps {
107+
fmt.Printf("%v\n", app)
87108
}
88109
}
89110

0 commit comments

Comments
 (0)