flexkit query
Runs a GraphQL query or mutation against the project’s GraphQL API and prints the JSON response on stdout. It uses your CLI credentials, so you don’t need to create an API token or set headers.
The operation can be inline text, a .graphql file, or - to read it from stdin. GraphQL errors are printed on stderr, and the command exits with code 1, so scripts can stop on errors.
Synopsis
flexkit query <operation|file|-> [--var <key=value>]... [--variables <json|@file|->] [--data-only] [--project <id>]Examples
# Query the first five products
flexkit query '{ products(limit: 5) { _id sku name { default } } }'
# Run a query from a file with variables
flexkit query ./queries/orders-by-status.graphql --var status=PAID --var limit=20
# Pass all variables at once from a JSON file
flexkit query ./mutations/update-price.graphql --variables @vars.json
# Pipe an operation in and keep only the data
cat query.graphql | flexkit query - --data-only | jq '.products[].name'
# Query another project than the linked one
flexkit query ./queries/products.graphql --project abcdefghijA file with variables looks like any GraphQL document:
# queries/orders-by-status.graphql
query OrdersByStatus($status: String!, $limit: Int) {
orders(where: { status: { eq: $status } }, limit: $limit) {
_id
total
customer {
email
}
}
}Variables
--var key=valuesets one variable and can be repeated. Values are parsed as JSON when possible:--var limit=20is a number,--var active=trueis a boolean,--var 'ids=["a","b"]'is a list, and anything else is a string. Dotted keys build objects:--var input.price=10sends{ "input": { "price": 10 } }.--variablestakes a whole JSON object, inline, as@file, or-for stdin.
When you use both, --var values override the same keys from --variables.
Options
You can also use all global options.
Notes
- Your role and space memberships apply, exactly as in Studio: a viewer can query but can’t run mutations.
- To explore the schema, run
flexkit schema show, or use the Explorer in Studio. - For simple reads and writes without GraphQL, use
flexkit records.
Last updated on