Skip to content

flowctl: add raw graphql commands to introspect and call the GraphQL API - #3352

Draft
GregorShear wants to merge 1 commit into
masterfrom
greg/flowctl-graphql
Draft

flowctl: add raw graphql commands to introspect and call the GraphQL API#3352
GregorShear wants to merge 1 commit into
masterfrom
greg/flowctl-graphql

Conversation

@GregorShear

Copy link
Copy Markdown
Contributor

Description:

Adds flowctl raw graphql, the GraphQL counterpart of raw get / rpc / update: exec runs a query or mutation, and schema / types / describe / operations render the schema read by introspection.

Workflow steps:

flowctl raw graphql operations mutation --search invite   # what can I call?
flowctl raw graphql describe InviteLink                   # what shape is it?
flowctl raw graphql exec 'query { alertTypes { alertType } }'
flowctl raw graphql exec --var cap=read \
  'query Q($cap: Capability!) { prefixes(by: {minCapability: $cap}) { edges { node { prefix } } } }'

Documentation links affected:

None. crates/flowctl/README.md gained a usage section.

Notes for reviewers:

  • Introspection means output describes the API the active profile points at, not the SDL this binary was built against.
  • schema output was diffed against crates/flow-client/control-plane-api.graphql to validate the renderer. It matches, except that a documented argument list gets one argument per line — async_graphql's own SDL export only breaks before arguments carrying a description and runs the rest together.
  • exec prints JSON unless -o yaml, so pipes into jq work. It exits non-zero on GraphQL errors, which arrive with an HTTP 200.
  • Verified against a local stack: authenticated and anonymous queries, a mutation from --file and from stdin, and the error path.

…L API

`flowctl raw get` / `rpc` / `update` reach the PostgREST API ad hoc, but the
GraphQL API had no equivalent: calling it meant writing a typed
`graphql_client` query and rebuilding, and learning its shape meant reading
the checked-in SDL or opening GraphiQL in a browser.

Add `flowctl raw graphql`, with five subcommands:

- `exec` posts a document taken from an argument, `--file`, or stdin, with
  variables from `--variables` (a JSON object) and repeated `--var name=value`
  pairs. A `--var` value is used as JSON when it parses as JSON and as a
  string otherwise, so both `--var first=10` and `--var prefix=acmeCo/` pass
  what the caller means. The whole response envelope is printed, errors
  included, and the command exits non-zero when the API reported any — a
  GraphQL error arrives with an HTTP 200 and would otherwise look like
  success to a script.
- `schema` prints the schema as SDL, or as the raw introspection response for
  other tooling.
- `types` and `operations` list the schema's types and its callable query and
  mutation fields, filterable by kind, root, and name.
- `describe` prints one type's definition, matching case-insensitively and
  suggesting similar names on a miss.

Every command but `exec` reads the schema by introspection, so it describes
the API the active profile points at rather than whatever SDL this binary was
built against. SDL rendering follows the conventions of the schema that
control-plane-api emits into crates/flow-client/control-plane-api.graphql, so
the two can be diffed to find where a client's generated types have fallen
behind the deployed API. The one departure is that a documented argument list
puts each argument on its own line, where async-graphql's own SDL export only
breaks before arguments carrying a description and runs the rest together.

`exec` and `schema --format introspection` print JSON unless `--output yaml`
is given: a GraphQL response has no fixed columns to tabulate, and the usual
"YAML when stdout isn't a terminal" default would break pipes into `jq`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant