CLI Usage
Master the Zeus command-line interface to generate powerful type-safe GraphQL clients.
Basic Syntax
zeus <schema-source> <output-directory> [options]Schema Sources
Zeus can generate clients from multiple sources:
HTTP Endpoint
zeus https://your-api.com/graphql ./src/zeusLocal Schema File
zeus ./schema.graphql ./src/zeus
zeus ./schema.gql ./src/zeusIntrospection JSON
zeus ./introspection.json ./src/zeusFrom Multiple Files
zeus "./schemas/**/*.graphql" ./src/zeusCommand Options
--header or -h
Add custom headers for schema introspection:
zeus https://api.com/graphql ./src/zeus \
--header "Authorization: Bearer token" \
--header "X-API-Key: key123"--typedDocumentNode or -t
Generate TypedDocumentNode exports for Apollo Client, urql, etc.:
zeus https://api.com/graphql ./src/zeus --typedDocumentNodeThis creates additional TypedDocumentNode exports in typedDocumentNode.ts.
--apollo
Optimize for Apollo Client integration:
zeus https://api.com/graphql ./src/zeus --apollo--jsonSchema
Generate JSON Schema alongside TypeScript types:
zeus https://api.com/graphql ./src/zeus --jsonSchema--help
Display help information:
zeus --help--version or -v
Show Zeus version:
zeus --versionConfiguration File
Create a zeus.config.json for reusable configuration:
{
"schema": "https://your-api.com/graphql",
"output": "./src/zeus",
"headers": {
"Authorization": "Bearer ${API_TOKEN}",
"X-Custom-Header": "value"
},
"typedDocumentNode": true,
"scalars": {
"DateTime": "string",
"JSON": "Record<string, any>",
"Upload": "File"
}
}Then run Zeus without arguments:
zeusOr specify the config file:
zeus --config ./custom-config.jsonEnvironment Variables
Use environment variables in configuration:
{
"schema": "${GRAPHQL_ENDPOINT}",
"output": "./src/zeus",
"headers": {
"Authorization": "Bearer ${API_TOKEN}"
}
}Set in your environment:
export GRAPHQL_ENDPOINT=https://api.com/graphql
export API_TOKEN=your_token_here
zeusCommon Workflows
Development Setup
Generate client with TypedDocumentNode for React:
zeus https://api.com/graphql ./src/zeus --typedDocumentNodeCI/CD Pipeline
Add to your CI pipeline:
# Install Zeus
npm install -D graphql-zeus
# Generate in build
npx zeus https://api.com/graphql ./src/zeusWatch Mode (with nodemon)
Auto-regenerate on schema changes:
npm install -D nodemon{
"scripts": {
"zeus:watch": "nodemon --watch schema.graphql --exec 'zeus schema.graphql ./src/zeus'"
}
}Multiple Environments
{
"scripts": {
"zeus:dev": "zeus https://dev-api.com/graphql ./src/zeus",
"zeus:staging": "zeus https://staging-api.com/graphql ./src/zeus",
"zeus:prod": "zeus https://api.com/graphql ./src/zeus"
}
}Schema Download
Download and save schema for offline use:
# Introspect and save
zeus https://api.com/graphql ./src/zeus --download-schema
# This saves schema.graphql in output directory
# Now you can use the local file
zeus ./src/zeus/schema.graphql ./src/zeusCustom Scalar Mapping
Map custom scalars to TypeScript types:
zeus https://api.com/graphql ./src/zeus \
--scalar DateTime=string \
--scalar JSON="Record<string, any>" \
--scalar Upload=FileOr in config file:
{
"scalars": {
"DateTime": "string",
"JSON": "Record<string, any>",
"Upload": "File",
"BigInt": "bigint",
"UUID": "string"
}
}Output Structure
Zeus generates the following structure:
src/zeus/
├── index.ts # Main file with Chain, Selector, etc.
├── const.ts # Constants and utility functions
├── typedDocumentNode.ts # TypedDocumentNode exports (if enabled)
└── zeus.config.json # Generated configurationIntegration with Build Tools
package.json Scripts
{
"scripts": {
"generate": "zeus https://api.com/graphql ./src/zeus",
"generate:watch": "nodemon --exec npm run generate",
"prebuild": "npm run generate",
"build": "tsc",
"dev": "npm run generate && ts-node src/index.ts"
}
}With Webpack
const { execSync } = require('child_process');
module.exports = {
// ... other config
plugins: [
{
apply: (compiler) => {
compiler.hooks.beforeCompile.tap('ZeusPlugin', () => {
execSync('npx zeus https://api.com/graphql ./src/zeus');
});
},
},
],
};With Vite
import { defineConfig } from 'vite';
import { exec } from 'child_process';
export default defineConfig({
plugins: [
{
name: 'zeus-generator',
buildStart() {
return new Promise((resolve, reject) => {
exec('npx zeus https://api.com/graphql ./src/zeus', (error) => {
if (error) reject(error);
else resolve();
});
});
},
},
],
});Authentication Patterns
Basic Auth
zeus https://api.com/graphql ./src/zeus \
--header "Authorization: Basic $(echo -n user:pass | base64)"Bearer Token
zeus https://api.com/graphql ./src/zeus \
--header "Authorization: Bearer ${TOKEN}"API Key
zeus https://api.com/graphql ./src/zeus \
--header "X-API-Key: ${API_KEY}"Custom Auth
zeus https://api.com/graphql ./src/zeus \
--header "X-Custom-Auth: ${AUTH_VALUE}" \
--header "X-User-ID: ${USER_ID}"Troubleshooting
Network Errors
# Increase timeout
zeus https://slow-api.com/graphql ./src/zeus --timeout 30000SSL Errors
# Skip SSL verification (not recommended for production)
NODE_TLS_REJECT_UNAUTHORIZED=0 zeus https://api.com/graphql ./src/zeusLarge Schemas
# Increase Node memory
NODE_OPTIONS="--max-old-space-size=4096" zeus https://api.com/graphql ./src/zeusBest Practices
- Version Control - Commit generated files for reproducible builds
- CI/CD - Always regenerate in CI to catch schema changes
- Configuration File - Use
zeus.config.jsonfor consistency - Environment Variables - Never commit sensitive tokens
- Watch Mode - Use in development for live updates
Next Steps
- Your First Query - Learn how to use the generated client
- Chain Client - Simple query/mutation client
- Thunder Client - Custom fetch implementation
Command Reference
| Command | Description |
|---|---|
zeus <source> <output> | Generate client |
zeus --version | Show version |
zeus --help | Show help |
zeus --typedDocumentNode | Generate TypedDocumentNode |
zeus --header "<name>: <value>" | Add header |
zeus --config <file> | Use config file |