api

package
v1.20.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 13 Imported by: 0

README

spacectl api

spacectl api lets you run ad-hoc read-only GraphQL queries against the Spacelift API using your existing authentication.

Mutations are not supported. For write operations, use the dedicated spacectl subcommands or the Spacelift Terraform Provider.

Usage

Basic queries (bare field selections are wrapped in query { ... } automatically):

spacectl api 'stacks { id name state }'
spacectl api 'workerPools { id name workers { id } }'

Full query syntax:

spacectl api 'query { stack(id: "my-stack") { id name branch repository } }'

With variables:

spacectl api --variables '{"id":"my-stack"}' 'query($id: ID!) { stack(id: $id) { id name } }'

From a file or stdin:

spacectl api < query.graphql
spacectl api --variables '{"id":"my-stack"}' < query.graphql
cat query.graphql | spacectl api

Output

  • When stdout is a TTY, output is pretty-printed JSON.
  • When piped, output is raw JSON (suitable for jq).
  • Use --raw to force raw output.
spacectl api 'stacks { id name repository }' | jq '.data.stacks[] | select(.repository == "tf-infra")'

Schema Introspection

Use --schema to dump the full GraphQL schema via introspection:

# Full schema dump
spacectl api --schema > schema.json

# List all query names
spacectl api --schema | jq '[.data.__schema.types[] | select(.name == "Query") | .fields[].name] | sort'

# List all mutation names
spacectl api --schema | jq '[.data.__schema.types[] | select(.name == "Mutation") | .fields[].name] | sort'

# Inspect a specific type
spacectl api --schema | jq '.data.__schema.types[] | select(.name == "Stack")'

# List enum values
spacectl api --schema | jq '.data.__schema.types[] | select(.name == "RunState") | .enumValues[].name'

You can also run targeted introspection queries directly:

# List all queries
spacectl api '{ __type(name: "Query") { fields { name } } }' | jq '.data.__type.fields[].name'

# Inspect a specific query's arguments
spacectl api '{ __type(name: "Query") { fields { name args { name type { name kind ofType { name } } } } } }' \
  | jq '.data.__type.fields[] | select(.name == "stack")'

# List all types (excluding internals)
spacectl api '{ __schema { types { name kind } } }' | jq '[.data.__schema.types[] | select(.name | startswith("__") | not) | .name] | sort'

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command

func Command() cmd.Command

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL