[eas-cli] Add pagination to supported GQL queries
Checklist
- [ ] I've added an entry to CHANGELOG.md if necessary. You can comment this pull request with
/changelog-entry [breaking-change|new-feature|bug-fix|chore] [message]and CHANGELOG.md will be updated automatically.
Why
Closes ENG-5322
How
Unfortunately, this is a pretty beefy PR 🐮
IMO, we had two options to add pagination to our CLI. The first option was to copy something like the aws-cli pagination options and add flags for each command that control that logic (e.g. --offset and --pageSize). The second option was to create an interactive selector for each command, where users could select whether they wanted to fetch more pages.
The pros of the first option are its simplicity, and that it lends itself well to automation. The pros of the second option are that it's a nicer experience for humans, especially newer users, and that it doesn't force me to change the flags on a bunch of commands.
I ended up going with the second option.
I created a generic-ish function performPaginatedQuery that will operate on and return whatever T the caller provides (think GQL types like BuildFragment or Update). The function will recursively call itself while incrementing its offset until no more items are returned. I provided a callback where users can define how the specific query should be executed and what results should be saved from it.
performPaginatedQuery is accepts an arg promptOptions that is of type confirm or select. This controls how the user interacts with the CLI. select prompts require a user to select a list item and performPaginatedQuery return that value when the function finishes execution. confirm prompts require a user to approve querying for an additional page of items if there are more pages left, and return always an empty array of QueryReturnType.
Shoutouts to @FiberJW who paired with me on some of this 👍
Test Plan
I manually tested each flow for each command that was affected. There's quite a bit here, so I may have missed some flow somewhere. Commands affected:
- branch/list.ts
- branch/view.ts
- build/cancel.ts
- build/list.ts
- channel/list.ts
- channel/rollout.ts
- channel/view.ts
- update/index.ts
- update/list.ts
-
--non-interactive+--jsonif those flags are applicable to those commands. (Assuming that prompting the user for input when--jsonis present will not break anything.)
Preview Videos
Confirm (list and view commands)
https://user-images.githubusercontent.com/15132641/177445637-91c35951-85a8-4597-b116-76d4767ef711.mov
Select
https://user-images.githubusercontent.com/15132641/177616248-3c8fdb7b-2a49-4f1c-a8e7-d56031511445.mov
ENG-5322 Add pagination to EAS CLI for EAS Update
ENG-5028 added support for paginating updates, branches, and channels on the website (also I believe deployments, the combo of channels+branches, were already paginated).
We also need to add pagination to EAS CLI. One area we need this is https://github.com/expo/eas-cli/blob/main/packages/eas-cli/src/graphql/queries/UpdateQuery.ts#L18-L60 but there may be more.
I noticed we don't use /Users/kirby/Expo/eas-cli/packages/eas-cli/src/graphql/queries/SubmissionQuery.ts anywhere. Should we remove it?
Size Change: -216 B (0%)
Total Size: 25.1 MB
| Filename | Size | Change |
|---|---|---|
./packages/eas-cli/dist/eas-linux-x64.tar.gz |
25.1 MB | -216 B (0%) |
Codecov Report
Merging #1197 (f5191b2) into main (d0b9af2) will decrease coverage by
0.13%. The diff coverage is22.53%.
@@ Coverage Diff @@
## main #1197 +/- ##
==========================================
- Coverage 51.33% 51.20% -0.12%
==========================================
Files 373 374 +1
Lines 13329 13471 +142
Branches 2739 2779 +40
==========================================
+ Hits 6841 6897 +56
- Misses 5974 6056 +82
- Partials 514 518 +4
| Impacted Files | Coverage Δ | |
|---|---|---|
| packages/eas-cli/src/commands/channel/rollout.ts | 13.08% <ø> (ø) |
|
| packages/eas-cli/src/commands/channel/view.ts | 20.00% <0.00%> (ø) |
|
| packages/eas-cli/src/graphql/queries/BuildQuery.ts | 41.67% <ø> (ø) |
|
| packages/eas-cli/src/graphql/types/UpdateBranch.ts | 100.00% <ø> (ø) |
|
| packages/eas-cli/src/log.ts | 80.71% <0.00%> (-2.93%) |
:arrow_down: |
| packages/eas-cli/src/commands/update/list.ts | 22.79% <3.04%> (-2.97%) |
:arrow_down: |
| packages/eas-cli/src/commands/branch/view.ts | 31.04% <4.35%> (-4.38%) |
:arrow_down: |
| packages/eas-cli/src/commands/build/list.ts | 23.46% <8.70%> (-0.59%) |
:arrow_down: |
| packages/eas-cli/src/commands/channel/list.ts | 24.29% <9.10%> (-16.89%) |
:arrow_down: |
| packages/eas-cli/src/commands/build/cancel.ts | 22.23% <10.00%> (+1.96%) |
:arrow_up: |
| ... and 11 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update d0b9af2...f5191b2. Read the comment docs.
i've broken this into other, smaller PRs. closing this one since it's redundant.