Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge JSON responses from
gh api
#8620Merge JSON responses from
gh api
#8620Changes from 10 commits
8e27e9a
a651036
e7f5dde
310e552
48f0cd6
0dfe6ec
f41876d
e83e049
a76af85
4ea7bca
2758b80
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @heaths, one of the issues with long running PRs like this is remembering all the context. When I played around with this just now I anticipated that for REST endpoints
--paginate --slurp
would be the same as--paginate
since the content of REST responses already get slurped into an array. However what happens is we end up doubly nesting the array:Maybe my assumption is bad and we always want to apply the same semantics to
--slurp
even if it produces a strange result - we already know that the whole pagination is kind of quirky. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was how it originally worked, but then someone noted it didn't "solve" their problem of merging nested arrays - only top-level arrays. I still think that's up to business logic - there's no way for us to know which level of arrays to merge - but in the discussion above I agreed to just wrap everything in an array like
jq --slurp
so that we at least return valid JSON. That's all this PR has ever been about: returning valid JSON such that you can pipe it to something that requires it - notjq
, but something like PowerShell'sConvertFrom-Json
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember that discussion as it related to the GQL requests and I agree that we cannot know that and the consumer needs to determine that themselves.
To be clear, here I'm describing the existing merging of JSON array REST responses already getting slurped by
--paginate
with no further work (as far as I can tell). Below in the screenshot you can see the difference between./bin/gh api --paginate repos/cli/go-gh/release
and./bin/gh api --paginate --slurp repos/cli/go-gh/release
. The--slurp
results in a double nesting of arrays with the top level one only having one item.It's just a bit of a weird situation that the REST pagination ends up creating a single array object that the slurp then wraps in another array. I'm not sure there is a good solution to this though, except perhaps only allowing
--slurp
on graphql paginated requests? In any case someone is liable to get confused, so maybe we just ship this and move on with our lives.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was the compromised we discussed in our meeting with @andyfeller as well: we'd mimic
jq --slurp
exactly, which also double-nests arrays. This way, the result is consistent: it's always an array. The array items are each page of the response regardless of whether it's an array or object. No guesswork as to how best to handle the output: it's always an array of each page. If you don't need that for a REST response of arrays, don't pass--slurp
: you'll already get a merged array because of Nate's previous change based on my old PR.I'd rather have consistency than conditional output formats myself. Easier to code without having to think of whether I'm making a REST call or GraphQL call.