nitrogql logonitrogql

nitrogql CLI Usage

nitrogql provides a CLI to check your GraphQL code and to generate types from your schema and operations.

The CLI is installed with npm:

npm install --save-dev @nitrogql/cli

commands

Basic usage of the CLI is:

nitrogql <command> [options]

The following commands are available.

💡 generate also implies check. GraphQL code is checked before types are generated.

options

--config-file

Specify the path to the configuration file. By default, the CLI looks for graphql.config.yaml in the current directory.

npx nitrogql generate --config-file ./path/to/config.yaml

--schema

Specify the path to the schema file(s). This overrides the schema path specified in the configuration file.

--operation

Specify the path to the operation file(s). This overrides the operation path specified in the configuration file.

--output-format

Specify the output format of the CLI. Possible values are:

The signature of the json output is:

interface CLIOutput {
  /**
   * Exists when a command fails.
   */
  error?: {
    /**
     * Command name that had error.
     */
    command: string | null;
    /**
     * Error message.
     */
    message: string;
  }
  /**
   * Exists when the 'check' command is run.
   */
  check?: {
    /**
     * List of errors.
     * Empty when the check is successful.
     */
    errors: {
      fileType: "schema" | "operation";
      file?: {
        path: string;
        // line and column are 0-indexed
        line: number;
        column: number;
      }
      message: string;
    }[]
  }
  /**
   * Exists when the 'generate' command is run.
   */
  generate?: {
    /**
     * List of output files.
     */
    files: { 
      fileType:
        | "schemaTypeDefinition"
        | "schemaTypeDefinitionSourceMap"
        | "operationTypeDefinition"
        | "operationTypeDefinitionSourceMap";
      path: string;
    }[];
  }
}

Notes on file system access

Due to the security nature of WASI, the CLI cannot access files outside the current directory by default. To allow access to files outside the current directory, use a NITROGQL_FS_SCOPE environment variable.

NITROGQL_FS_SCOPE=../ npx nitrogql check --config-file ../graphql.config.yaml