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:

Usage

Usage: turbot graphql [options]

The supported options are:

Usage: turbot graphql <subcommand> [options]

Instead of using the --query parameter, you can use any GraphQL resolver as a sub-command. Common subcommands include:

Queries that return a single item also support:

List queries also support: