@gqfn/cli
A command-line interface tool for managing GraphQL schemas with @gqfn/core.
Installation
npm install -g @gqfn/cli
Or use with npx:
npx @gqfn/cli
Commands
init
Initialize a new @gqfn configuration file in your project.
gqfn init [options]
Options:
-s, --silent
- Disable all output
This command creates a gqfn.config.ts
file with default configuration:
import { defineConfig } from '@gqfn/cli'
export default defineConfig({
output: './gqfn',
})
add
Add new GraphQL schema URLs to your configuration.
gqfn add <urls...> [options]
Arguments:
<urls...>
- One or more GraphQL schema URLs to add
Options:
-s, --silent
- Disable all output
Example:
gqfn add https://api.example.com/graphql https://api2.example.com/graphql
sync
Synchronize GraphQL schemas from configured clients and generate TypeScript definitions.
gqfn sync [options]
Options:
--ignore-error
- Continue execution even if some schemas fail to sync-s, --silent
- Disable all output
This command:
- Reads your configuration file
- Fetches schemas from all configured clients
- Generates TypeScript definition files in the output directory
- Names files using the pattern:
{hostname}_{hash}.d.ts
Configuration
The CLI uses a configuration file (gqfn.config.ts
or gqfn.config.js
) to define:
- clients: Array of GraphQL endpoints or client configurations
- output: Directory where generated types will be saved (default:
./gqfn
)
Example configuration:
import { defineConfig } from '@gqfn/cli'
export default defineConfig({
clients: [
'https://api.example.com/graphql',
{
url: 'https://api2.example.com/graphql',
loader: {
type: 'sdl',
value: '...' // SDL string
}
}
],
output: './generated/gqfn'
})
Programmatic Usage
You can also use the CLI functions programmatically:
import { init, add, sync } from '@gqfn/cli'
// Initialize configuration
await init({ silent: false })
// Add clients
await add({
clients: ['https://api.example.com/graphql'],
silent: false
})
// Sync schemas
await sync({
ignoreError: false,
silent: false
})
Generated Files
The sync command generates TypeScript definition files with names based on the schema URL:
api.example.com_abc123.d.ts
- Forhttps://api.example.com/graphql
localhost_def456.d.ts
- Forhttp://localhost:4000/graphql
Each file contains the complete TypeScript definitions for that GraphQL schema, ready to use with @gqfn/core.
Error Handling
By default, the CLI stops execution if any schema fails to sync. Use the --ignore-error
flag with the sync
command to continue processing other schemas even if some fail.
Examples
Complete workflow:
# Initialize project
gqfn init
# Add GraphQL endpoints
gqfn add https://countries.trevorblades.com/graphql
# Sync schemas and generate types
gqfn sync
Silent operation:
gqfn sync --silent --ignore-error