graphql

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

where ~/queries/query1.txt is a file containing the same query as above.

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 (or provide a default output for a type not yet implemented by the cli) by adding an entry to the cli config file: ~/.config/turbot/config.yyl

To override the default output for resource and control, add the following to the config:

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

graphql resource --id "tmod:@turbot/turbot#/"

This returns:

resource:
  type:
    uri: "tmod:@turbot/turbot#/resource/types/turbot"
  turbot:
    id: "165643650699265"
    parentId: null
    title: Turbot

Query resource by id, returning custom output fields

The output may be either a format string or a file path:

turbot graphql resource --id "tmod:@turbot/turbot#/" --output '{ title }'

or

turbot graphql resource --id "tmod:@turbot/turbot#/" --output ~/queries/resourceOutput.txt

where ~/queries/resourceOutput.txt is a file containing the same output format text as above.

These return

resource:
  title: Turbot

Awaiting expected graphql output

If the --expected argument is provided, the cli will check the results of the graphql query against the expected result and if they not match it will retry every 5 seconds for up to a minute (by default).

For example:

turbot graphql resource-list --filter "resourceType:folder waitTest" --output {items{title}} --expected ~/queries/expected1.yml

Where expected1.yml is:

resourceList:
  items:
    - title: waitTest

This query will retry until the result matches the expected value.

Notes:

Usage

Usage: turbot graphql [options]

The turbot graphql command executes graphql queries against a Turbot Guardrails workspace. You can use the --query to specify the full graphql query to run

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:

The supported options vary by sub-command, but most support:

Queries that return a single item (turbot graphql resource, turbot graphql control, etc) also support:

List queries (turbot graphql resources, turbot graphql controls, etc) also support: