UNPKG

@graphql-hive/cli

Version:

A CLI util to manage and control your GraphQL Hive

385 lines • 20.2 kB
import { GraphQLError, Source } from 'graphql'; import { CLIError } from '@oclif/core/lib/errors'; import { CompositionFailure } from '@theguild/federation-composition'; import { FragmentType } from '../gql/index'; import { RenderErrors_SchemaErrorConnectionFragment } from './schema'; export declare enum ExitCode { SUCCESS = 0, ERROR = 1, TIMED_OUT = 2, BAD_INIT = 3 } export declare const exitCodeDescriptions: Record<ExitCode, string>; export declare const ERRORS_DOCS_URL = "https://the-guild.dev/graphql/hive/docs/api-reference/cli"; export declare function errorDocsAnchor(code: number): string; export interface HiveCLIErrorClass { readonly name: string; readonly code: number; readonly exitCode: ExitCode; readonly title: string; readonly fix: string; } export declare abstract class HiveCLIError extends CLIError { static readonly code: number; static readonly exitCode: ExitCode; static readonly title: string; static readonly fix: string; readonly exitCode: ExitCode; readonly errorCode: number; /** The message without the error code and the link to the documentation. */ readonly plainMessage: string; constructor(message: string); } export declare const errorCategories: ReadonlyArray<{ name: string; start: number; }>; export declare class InvalidConfigError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Invalid configuration file"; static readonly fix = "Fix the reported problem in `hive.json` (or the file set with `HIVE_CONFIG`). Supported keys are `registry.endpoint`, `registry.accessToken`, `registry.headers`, `cdn.endpoint` and `cdn.accessToken`. When `HIVE_SPACE` is set, the file must contain a top-level key with that name."; constructor(configPath: string, reason: string); } export declare class InvalidCommandError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Unknown command"; static readonly fix = "Run `hive help` to list the available commands and check the spelling."; constructor(command: string); } export declare class MissingArgumentsError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Missing required argument"; static readonly fix = "Provide the listed arguments or flags. Organization access tokens always require the `--target` flag."; constructor(...requiredArgs: Array<[string, string]>); } export declare class MissingRegistryTokenError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Missing registry access token"; static readonly fix = "Pass `--registry.accessToken`, set `HIVE_TOKEN`, or set `registry.accessToken` in `hive.json`."; constructor(); } export declare class MissingCdnKeyError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Missing CDN access token"; static readonly fix = "Pass `--cdn.accessToken`, set `HIVE_CDN_ACCESS_TOKEN`, or set `cdn.accessToken` in `hive.json`."; constructor(); } export declare class MissingEndpointError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Missing registry endpoint"; static readonly fix = "Pass `--registry.endpoint`, set `HIVE_REGISTRY`, or set `registry.endpoint` in `hive.json`. Make sure `HIVE_REGISTRY` is not set to an empty string."; constructor(); } export declare class InvalidRegistryTokenError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Invalid registry access token"; static readonly fix = "Create a new access token, and check that the access token and the registry endpoint belong to the same Hive instance."; constructor(); } export declare class InvalidCdnKeyError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Invalid CDN access token"; static readonly fix = "Create a new CDN access token for the target, and check that it belongs to the same target as the CDN endpoint."; constructor(); } export declare class MissingCdnEndpointError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Missing CDN endpoint"; static readonly fix = "Pass `--cdn.endpoint`, set `HIVE_CDN_ENDPOINT`, or set `cdn.endpoint` in `hive.json`."; constructor(); } export declare class MissingEnvironmentError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Missing environment variable"; static readonly fix = "Set the listed environment variables. With `--github`, run the command in GitHub Actions or set `GITHUB_REPOSITORY`."; constructor(...requiredVars: Array<[string, string]>); } export declare class CommitRequiredError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Missing commit"; static readonly fix = "Pass `--commit` (or set `HIVE_COMMIT` for `schema:publish`), or run the command inside a git repository."; constructor(); } export declare class GithubRepositoryRequiredError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Missing GitHub repository"; static readonly fix = "Run the command in GitHub Actions, where `GITHUB_REPOSITORY` is set, or in a CI environment that exposes the repository."; constructor(); } export declare class AuthorRequiredError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Missing author"; static readonly fix = "Pass `--author` (or set `HIVE_AUTHOR` for `schema:publish`), or run the command inside a git repository with a configured user."; constructor(); } export declare class HTTPError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "HTTP error response"; static readonly fix = "A 4xx status usually means a wrong endpoint or a rejected request: check the endpoint URL and credentials. A 5xx status means the server failed: retry later."; constructor(endpoint: string, status: number, message: string); } export declare class NetworkError extends HiveCLIError { static readonly code: number; static readonly exitCode: ExitCode; static readonly title: string; static readonly fix: string; constructor(cause: Error | string, message?: string); } /** GraphQL Errors returned from an operation. Note that some GraphQL Errors that require specific steps to correct are handled through other error types. */ export declare class APIError extends HiveCLIError { graphQLErrors?: ReadonlyArray<GraphQLError> | undefined; static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "API error"; static readonly fix = "Read the message returned by the Hive API. Include the request ID when contacting support."; ref?: string; constructor(cause: Error | string, requestId?: string, graphQLErrors?: ReadonlyArray<GraphQLError> | undefined); } export declare class IntrospectionError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Introspection failed"; static readonly fix = "Make sure the service is running, reachable and allows introspection, or pass the schema file instead of the URL."; /** @param service The name or URL of the service. */ constructor(service?: string); } export declare class UnsupportedFileExtensionError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Unsupported file extension"; static readonly fix = "Use one of the supported file extensions listed in the message."; constructor(filename: string, supported?: string[]); } export declare class FileMissingError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "File not found"; static readonly fix = "Check that the path or glob matches at least one readable file."; constructor(fileName: string, additionalContext?: string); } export declare class InvalidFileContentsError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Invalid file contents"; static readonly fix = "Make sure the file is readable and contains valid content in the expected format."; constructor(fileName: string, expectedFormat: string); } export declare class InvalidTargetError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Invalid target"; static readonly fix = "Pass the target as a slug in the form `organization/project/target`, or as a target UUID."; constructor(flagName?: string); } export declare class InvalidFederationSubgraphError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Not a Federation subgraph"; static readonly fix = "Point the URL at a Federation subgraph that exposes `Query._service.sdl`, or pass the schema file instead."; constructor(reason?: string); } export declare class InvalidVersionIdError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Invalid schema version ID"; static readonly fix = "Pass the ID of a schema version from the same project as the target."; constructor(flagName?: string, reason?: string); } export declare class ConflictingOptionsError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Conflicting options"; static readonly fix = "Provide only one of the listed options."; constructor(flagNames: string[], reason?: string); } /** The API rejected the action for an authenticated token (GraphQL error code UNAUTHORISED). */ export declare class AccessDeniedError extends HiveCLIError { readonly permission: string | null; static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Access denied"; static readonly fix = "Grant the named permission to the access token, check that `--target` points at an existing target the token can access, or use an organization access token."; ref?: string; constructor(reason: string, permission: string | null, requestId?: string); } /** The API rejected the request during GraphQL validation, because the server does not know a field, argument or type the CLI sends. */ export declare class UnsupportedServerError extends HiveCLIError { graphQLErrors: ReadonlyArray<GraphQLError>; static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Unsupported Hive server version"; static readonly fix = "Upgrade the Hive server to a version that supports this CLI version, or use an older CLI version that matches the server. Nothing was executed on the server."; constructor(endpoint: string, graphQLErrors: ReadonlyArray<GraphQLError>); } export declare class RequestTimeoutError extends NetworkError { static readonly code: number; static readonly exitCode = ExitCode.TIMED_OUT; static readonly title = "Request timed out"; static readonly fix = "The operation may have completed on the server. Check its result, for example in Hive Console or with `hive schema:fetch`, before retrying."; constructor(endpoint: string, cause: Error | string); } export declare class InvalidInputError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Invalid command input"; static readonly fix = "Check the arguments and flags with `hive help <command>`."; readonly showHelp: boolean; readonly parse: unknown; constructor(cause: Error & { showHelp?: boolean; parse?: unknown; }); } export declare class InvalidHeaderError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Invalid header"; static readonly fix = "Use the `Name=Value` format for `--registry.header` and the `Name:Value` format for `--header`."; constructor(header: string, format: 'Name=Value' | 'Name:Value'); } export declare class UnexpectedError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Unexpected error"; static readonly fix = "Re-run the command with `DEBUG=*` for more details, and report the output if the problem persists."; constructor(cause: unknown); } export declare class SchemaFileNotFoundError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Schema not found"; static readonly fix = "Check the file path, glob or URL. For a URL, make sure the service is reachable."; constructor(fileName: string, reason?: string | Error); } export declare class SchemaFileEmptyError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "No type definitions found"; static readonly fix = "Make sure the schema contains GraphQL type definitions. In code files, the definitions must be in a template literal tagged with `gql` or `graphql`, or marked with a `/* GraphQL */` comment."; constructor(fileName: string); } export declare class SchemaCheckFailedError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Schema check failed"; static readonly fix = "Review the errors and breaking changes in the output or the linked report. Fix them, approve expected breaking changes in Hive Console, or use `--forceSafe`."; constructor(); } export declare class SchemaCheckApprovalFailedError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Schema check approval failed"; static readonly fix = "Make sure the access token has the `schemaCheck:approve` permission and that the failed schema check was stored by the registry."; constructor(reason: string); } export declare class SchemaPublishFailedError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Schema publish failed"; static readonly fix = "The schema was rejected and nothing was stored. Fix the reported errors and publish again."; constructor(details?: string | null); } export declare class InvalidSDLError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Invalid SDL"; static readonly fix = "Fix the GraphQL syntax error at the reported location."; constructor(err: GraphQLError); } export declare class SchemaPublishMissingServiceError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Missing service name"; static readonly fix = "Pass `--service <name>`. Federation and schema stitching projects require a service name."; constructor(message: string); } export declare class SchemaPublishMissingUrlError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Missing service URL"; static readonly fix = "Pass `--url <url>`. A service needs a URL the first time it is published, and the URL must be valid."; constructor(message: string); } export declare class PersistedOperationsMalformedError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Malformed persisted documents"; static readonly fix = "Use a GraphQL Code Generator, Relay or Apollo persisted query manifest, a directory of `.graphql` files, or a glob that matches `.graphql` files containing operations."; constructor(file: string, reason?: string); } export declare class SchemaNotFoundError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Schema not found in the registry"; static readonly fix = "Publish a schema to the target first, or check the target, the commit and the `--type` value."; constructor(commit?: string); } export declare class InvalidSchemaError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Schema version is not valid"; static readonly fix = "The requested schema version is not valid. Use a different commit, or fix and publish the schema again."; constructor(commit?: string); } export declare class ServiceAndUrlLengthMismatch extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.BAD_INIT; static readonly title = "Service and URL count mismatch"; static readonly fix = "Pass exactly one `--url` for every `--service`."; constructor(services: string[], urls: string[]); } export declare class LocalCompositionError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Local composition failed"; static readonly fix = "Fix the composition errors in the listed subgraphs."; constructor(compositionResult: CompositionFailure); } export declare class RemoteCompositionError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Remote composition failed"; static readonly fix = "Fix the composition errors in the listed subgraphs."; constructor(errors: FragmentType<typeof RenderErrors_SchemaErrorConnectionFragment>); } export declare class InvalidCompositionResultError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Invalid composition result"; static readonly fix = "The composed supergraph is invalid. Report the output as a bug."; /** Compose API spits out the error message */ constructor(supergraph?: string | undefined | null); } export declare class InvalidDocumentsError extends HiveCLIError { static readonly code: number; static readonly exitCode = ExitCode.ERROR; static readonly title = "Invalid operations"; static readonly fix = "Fix the listed operations so that they are valid against the schema."; constructor(invalidDocuments: Array<{ source: string | Source; errors: ReadonlyArray<GraphQLError>; }>); } /** Every error the CLI can report. Documentation is generated from this list. */ export declare const errorCatalog: ReadonlyArray<HiveCLIErrorClass>; export interface AggregateError extends Error { errors: Error[]; } export declare function isAggregateError(error: unknown): error is AggregateError; /** Whether the error, or one of its causes, is a request timeout (`AbortSignal.timeout`). */ export declare function isTimeoutError(error: unknown): boolean; //# sourceMappingURL=errors.d.ts.map