Command: graphql
Execute GraphQL queries against a Turbot Guardrails workspace.
Passing a Query on Command Line
The GraphQL query may be passed using the --query argument. This may be either a string query, or the path to a file containing the query:
turbot graphql --query '{ resource(id:"tmod:@turbot/turbot#/"){ turbot {title} } }'
or
turbot graphql --query ~/queries/query1.txt
These return:
resource:
turbot:
title: Turbot
Specify JSON Output Format
turbot graphql --query ~/queries/query1.txt --format json
This returns:
{
"resource": {
"turbot": {
"title": "Turbot"
}
}
}
Executing Specific Resolver
Instead of using the --query parameter, you can use any GraphQL resolver as a sub-command.
For many resolvers, the default GraphQL output is defined, so it is not required. You can override the default output by adding an entry to the CLI config file: ~/.config/turbot/config.yml
defaultGraphqlOutput:
resource: "{ title }"
control: " { state }"
Alternatively, you can specify the output data you wish GraphQL to return with the --output parameter.
Query Resource by ID, Returning Default Output Fields
turbot graphql resource --id "tmod:@turbot/turbot#/"
Query Resource by ID, Returning Custom Output Fields
turbot graphql resource --id "tmod:@turbot/turbot#/" --output '{ title }'
Testing Input Queries
The --runnable and --resource flags let you test control/policy input queries in their runnable context:
turbot graphql \
--query='{ resource { turbot { title } data } }' \
--runnable="tmod:@turbot/aws-s3#/control/types/bucketCmdb" \
--resource="arn:aws:s3:::my-bucket"
This executes the query using the same GraphQL schema that controls and calculated policies use at runtime. Useful for debugging what data a control/policy receives and testing input queries before deploying.
Awaiting Expected Output
If the --expected argument is provided, the CLI will check the results of the graphql query against the expected result and retry every 5 seconds for up to a minute (by default).
turbot graphql resource-list --filter "resourceType:folder waitTest" --output {items{title}} --expected ~/queries/expected1.yml
Notes:
- The expected argument (or file) should be json or yaml format text
- The timeout may be customized by passing the
--timeoutargument (in seconds)
Usage
Usage: turbot graphql [options]
The supported options are:
--expected: Either a file path to a yml/json file or a yml/json string containing expected result.--timeout: The number of seconds to retry the graphql query until the result matches the expected result. Default:60.--query: Either a file path to a file containing a graphql query, or a graphql query as a string.--variables: Either a file path to a yml/json file or a yml/json string containing the variables for the query.--output: Either a file path to a yml/json file or a yml/json string containing the graphql output data.--format: The format of the graphql results. Valid values areyaml(default) orjson.--runnable: A control or policy type URI for testing input queries.--resource: A resource ID or AKA for testing input queries. Must be used with--runnable.--profile: The Turbot Guardrails credentials profile to use.--credentials-file: Path to the shared credentials file. Default:~/.config/turbot/credentials.yml.--access-key: Turbot Guardrails access key.--secret-key: Turbot Guardrails secret access key.--workspace: Turbot Guardrails workspace URL.--help: Shows help.
Usage: turbot graphql <subcommand> [options]
Instead of using the --query parameter, you can use any GraphQL resolver as a sub-command. Common subcommands include:
turbot graphql resource --id <id>turbot graphql resource-list --filter "<filter>"turbot graphql control --id <id>turbot graphql controls --filter "<filter>"turbot graphql policy-value --id <id>turbot graphql policy-values --filter "<filter>"turbot graphql policy-setting --id <id>turbot graphql policy-settings --filter "<filter>"turbot graphql active-grants --filter "<filter>"turbot graphql notifications --filter "<filter>"
Queries that return a single item also support:
--id: an aka or id of the resource to return.
List queries also support:
--filter: A Turbot Guardrails filter to search for resources.--paging: A paging token to get the next batch of items.