-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration
The simplest way to set a custom endpoint:
export GRAPHQL_URL=https://api.example.com/graphql
gqlcli queriesCreate .gqlcli.json in your project directory to define named environments. This lets you switch between local, staging, prod, or any other environment without changing flags.
{
"default": "local",
"environments": {
"ENV_NAME": {
"url": "https://...",
"headers": {
"Header-Name": "value"
}
}
},
"operations": {
"OPERATION_NAME": {
"type": "query",
"query": "{ ... }",
"defaults": { "key": "value" }
}
}
}The operations map is optional. See Command-Reference#op for managing named operations. Query and mutation operations can be saved with gqlcli op save; subscription operations can be stored manually with "type": "subscription" and "query" or "subscription" content for use with gqlcli subscribe --op NAME.
{
"default": "local",
"environments": {
"local": {
"url": "http://localhost:8080/graphql",
"headers": {
"Authorization": "Bearer dev-token"
}
},
"staging": {
"url": "http://staging-api.example.com/graphql",
"headers": {
"Authorization": "Bearer staging-token",
"X-Tenant": "acme"
}
},
"prod": {
"url": "https://api.example.com/graphql",
"headers": {
"Authorization": "Bearer prod-token"
}
}
}
}# Uses the default environment (local)
gqlcli queries
# Explicitly select an environment
gqlcli queries --env prod
gqlcli query --query "{ users { id } }" --env staging
# Override URL on top of a named env
gqlcli queries --env staging --url http://other-host/graphqlEach directory can have its own .gqlcli.json. gqlcli looks for the config file only in the current working directory; it does not search parent directories or $HOME.
This means you typically choose one of:
- A single
.gqlcli.jsonper project (recommended) - A temporary ad‑hoc config in the directory where you are running
gqlcli
Authentication is done via HTTP headers in .gqlcli.json. Bearer token is the most common:
{
"environments": {
"prod": {
"url": "https://api.example.com/graphql",
"headers": {
"Authorization": "Bearer your-token-here"
}
}
}
}Any header can be added — API keys, custom auth schemes, tenant IDs:
{
"headers": {
"X-API-Key": "your-api-key",
"X-Tenant-ID": "acme-corp"
}
}When multiple URL sources are provided, higher items win:
| Priority | Source |
|---|---|
| 4 (highest) |
--url flag |
| 3 |
GRAPHQL_URL environment variable |
| 2 | Named environment in .gqlcli.json
|
| 1 (lowest) | Default http://localhost:8080/graphql
|
In addition to URL and headers, HTTP-backed commands accept transport controls:
gqlcli query '{ health }' --timeout 10 --retry 3 --retry-delay 500ms
gqlcli query --query-file ./ci-check.graphql --fail-on-graphql-errors
gqlcli queries --url https://localhost:8443/graphql --insecure-
--timeout SECONDSbounds the request. -
--retry Nretries transient connection failures, HTTP 408/429, and 5xx responses. -
--retry-delay DURATIONsets the delay between retries, for example500msor2s. -
--fail-on-graphql-errorsexits non-zero when the response has anerrorsarray. -
--insecureskips TLS certificate verification for self-signed/internal endpoints.
Log all HTTP requests and responses:
gqlcli query --query "{ users { id } }" --debugThis prints request headers, body, response status, and response body — useful for diagnosing auth or connectivity issues.