Repository navigation
feat(cmd/api): add api graphql for raw GraphQL requests - #283
Conversation
Add `zeabur api graphql`, which sends an arbitrary GraphQL request to the Zeabur API with the logged-in user's credentials and prints the raw JSON response, similar to `gh api graphql`. Scripts and coding agents can then read fields that no dedicated command exposes without handling the token. - `-f key=value` adds a string field, `-F key=value` a typed one (true/false/null/integers, `@file` / `@-`); `query` and `operationName` are top-level keys, everything else becomes a variable. - `--input file|-` reads a full JSON request body; fields merge on top. - Exits non-zero on HTTP failures or GraphQL errors while still printing the response body. - Adds `GraphQLRaw` to the API client, reusing the authenticated HTTP client. Co-authored-by: Yi-Jyun Pan <yjpan+main@zeabur.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6d4c303452
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Decode --input with UseNumber so integers beyond float64 precision are forwarded verbatim, and reject `null` or trailing data instead of panicking when fields are merged into a nil map. Co-authored-by: Yi-Jyun Pan <yjpan+main@zeabur.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1999f2a1be
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
`-F` previously fell back to a string for integers outside the int64 range. Send any integer literal as a JSON number verbatim; values with leading zeros such as `007` stay strings. Co-authored-by: Yi-Jyun Pan <yjpan+main@zeabur.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@opencodezebra review |
canyugs
left a comment
There was a problem hiding this comment.
LGTM. Logic is sound: single = cut keeps values with = intact, stdin is guarded against double reads, the body is printed even on error, and the three Codex findings (UseNumber, null input, big integers) are fixed with tests. CI is green.
Non-blocking: for agent use I would lean toward a --allow-mutation guard or at least a help-text note, but that can be a follow-up.
Summary
Adds
zeabur api graphql, a raw GraphQL escape hatch modeled aftergh api graphql. It sends any query to the Zeabur API with the logged-in user's existing credentials and prints the raw JSON response, so scripts and coding agents can read fields that no dedicated command exposes yet (e.g.Server.expiresAt,Server.isAutoRenewDisabled,SubscriptionStatus.nextBillingAt, AI Hub auto-recharge settings) without ever handling the token.Behavior
-f/--raw-field key=valueadds a string field;-F/--field key=valueadds a typed field (true/false/null/ integers,@fileor@-to read the value).queryandoperationNameare top-level request keys; every other field becomes a GraphQL variable.--input file|-reads a complete JSON request body;-f/-Ffields are merged on top of it. Standard input can only be consumed once.errors, and still prints the body so callers can inspect the details.zeabur auth login/ZEABUR_TOKEN) and works with--json(which only silences logs here). The token is never printed or logged, including with--debug.--workspaceand the saved context do not rewrite the request; team/project IDs must be passed explicitly as variables (documented in the help text and README).Implementation
pkg/api: newRawAPI.GraphQLRawon the client.Newnow keeps the authenticated*http.Clientso the raw request reuses the same OAuth2 transport and endpoint as the typed GraphQL client.internal/cmd/api+internal/cmd/api/graphql: new command package, registered in the root command.internal/cmd/api/graphql/graphql_test.go) cover field typing,@file,--input -merging, GraphQL/HTTP error exit codes, and invalid input.Testing
go build ./...,go vet ./...,go test ./...,golangci-lint runon the changed packages,gofumpt -lon new files.query { me { _id } }(exit 0), a query with variables,--json --input -from stdin, an invalid field (prints the 422 error body, exit 1), schema introspection confirmingServer.expiresAt,Server.isAutoRenewDisabledandSubscriptionStatus.nextBillingAtare reachable, and--debugoutput contains no auth header or token. No mutations were executed.Open question
Mutations are allowed, just like
gh api graphql. If maintainers would prefer a confirmation prompt or a--allow-mutationguard for agent use, happy to add it.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.