Skip to content

Commit

Permalink
Add detailed error message for Hive CLI missing access token (#6252)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdolle authored Jan 6, 2025
1 parent 817fed3 commit 5a6e565
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-files-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-hive/cli': patch
---

Print a detailed error when a command is executed without a hive access token
2 changes: 2 additions & 0 deletions packages/libraries/cli/src/commands/app/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Command from '../../base-command';
import { graphql } from '../../gql';
import { AppDeploymentStatus } from '../../gql/graphql';
import { graphqlEndpoint } from '../../helpers/config';
import { ACCESS_TOKEN_MISSING } from '../../helpers/errors';

export default class AppCreate extends Command<typeof AppCreate> {
static description = 'create an app deployment';
Expand Down Expand Up @@ -46,6 +47,7 @@ export default class AppCreate extends Command<typeof AppCreate> {
key: 'registry.accessToken',
args: flags,
env: 'HIVE_TOKEN',
message: ACCESS_TOKEN_MISSING,
});

const file: string = args.file;
Expand Down
2 changes: 2 additions & 0 deletions packages/libraries/cli/src/commands/app/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Flags } from '@oclif/core';
import Command from '../../base-command';
import { graphql } from '../../gql';
import { graphqlEndpoint } from '../../helpers/config';
import { ACCESS_TOKEN_MISSING } from '../../helpers/errors';

export default class AppPublish extends Command<typeof AppPublish> {
static description = 'publish an app deployment';
Expand Down Expand Up @@ -35,6 +36,7 @@ export default class AppPublish extends Command<typeof AppPublish> {
key: 'registry.accessToken',
args: flags,
env: 'HIVE_TOKEN',
message: ACCESS_TOKEN_MISSING,
});

const result = await this.registryApi(endpoint, accessToken).request({
Expand Down
3 changes: 3 additions & 0 deletions packages/libraries/cli/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import Command from '../base-command';
import { graphql } from '../gql';
import { graphqlEndpoint } from '../helpers/config';
import { ACCESS_TOKEN_MISSING } from '../helpers/errors';
import { loadSchema, renderErrors } from '../helpers/schema';
import { invariant } from '../helpers/validation';

Expand Down Expand Up @@ -204,6 +205,7 @@ export default class Dev extends Command<typeof Dev> {
legacyFlagName: 'token',
args: flags,
env: 'HIVE_TOKEN',
message: ACCESS_TOKEN_MISSING,
});

void this.watch(flags.watchInterval, serviceInputs, services =>
Expand Down Expand Up @@ -249,6 +251,7 @@ export default class Dev extends Command<typeof Dev> {
legacyFlagName: 'token',
args: flags,
env: 'HIVE_TOKEN',
message: ACCESS_TOKEN_MISSING,
});

return this.compose({
Expand Down
2 changes: 2 additions & 0 deletions packages/libraries/cli/src/commands/operations/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Args, Errors, Flags, ux } from '@oclif/core';
import Command from '../../base-command';
import { graphql } from '../../gql';
import { graphqlEndpoint } from '../../helpers/config';
import { ACCESS_TOKEN_MISSING } from '../../helpers/errors';
import { loadOperations } from '../../helpers/operations';

const fetchLatestVersionQuery = graphql(/* GraphQL */ `
Expand Down Expand Up @@ -95,6 +96,7 @@ export default class OperationsCheck extends Command<typeof OperationsCheck> {
args: flags,
legacyFlagName: 'token',
env: 'HIVE_TOKEN',
message: ACCESS_TOKEN_MISSING,
});
const graphqlTag = flags.graphqlTag;
const globalGraphqlTag = flags.globalGraphqlTag;
Expand Down
2 changes: 2 additions & 0 deletions packages/libraries/cli/src/commands/schema/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Args, Errors, Flags } from '@oclif/core';
import Command from '../../base-command';
import { graphql } from '../../gql';
import { graphqlEndpoint } from '../../helpers/config';
import { ACCESS_TOKEN_MISSING } from '../../helpers/errors';
import { gitInfo } from '../../helpers/git';
import {
loadSchema,
Expand Down Expand Up @@ -169,6 +170,7 @@ export default class SchemaCheck extends Command<typeof SchemaCheck> {
args: flags,
legacyFlagName: 'token',
env: 'HIVE_TOKEN',
message: ACCESS_TOKEN_MISSING,
});
const sdl = await loadSchema(file);
const git = await gitInfo(() => {
Expand Down
2 changes: 2 additions & 0 deletions packages/libraries/cli/src/commands/schema/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Args, Errors, Flags, ux } from '@oclif/core';
import Command from '../../base-command';
import { graphql } from '../../gql';
import { graphqlEndpoint } from '../../helpers/config';
import { ACCESS_TOKEN_MISSING } from '../../helpers/errors';
import { renderErrors } from '../../helpers/schema';

const schemaDeleteMutation = graphql(/* GraphQL */ `
Expand Down Expand Up @@ -110,6 +111,7 @@ export default class SchemaDelete extends Command<typeof SchemaDelete> {
args: flags,
legacyFlagName: 'token',
env: 'HIVE_TOKEN',
message: ACCESS_TOKEN_MISSING,
});

const result = await this.registryApi(endpoint, accessToken).request({
Expand Down
2 changes: 2 additions & 0 deletions packages/libraries/cli/src/commands/schema/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Args, Flags } from '@oclif/core';
import Command from '../../base-command';
import { graphql } from '../../gql';
import { graphqlEndpoint } from '../../helpers/config';
import { ACCESS_TOKEN_MISSING } from '../../helpers/errors';

const SchemaVersionForActionIdQuery = graphql(/* GraphQL */ `
query SchemaVersionForActionId(
Expand Down Expand Up @@ -83,6 +84,7 @@ export default class SchemaFetch extends Command<typeof SchemaFetch> {
args: flags,
legacyFlagName: 'token',
env: 'HIVE_TOKEN',
message: ACCESS_TOKEN_MISSING,
});

const actionId: string = args.actionId;
Expand Down
2 changes: 2 additions & 0 deletions packages/libraries/cli/src/commands/schema/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Args, Errors, Flags } from '@oclif/core';
import Command from '../../base-command';
import { DocumentType, graphql } from '../../gql';
import { graphqlEndpoint } from '../../helpers/config';
import { ACCESS_TOKEN_MISSING } from '../../helpers/errors';
import { gitInfo } from '../../helpers/git';
import { loadSchema, minifySchema, renderChanges, renderErrors } from '../../helpers/schema';
import { invariant } from '../../helpers/validation';
Expand Down Expand Up @@ -193,6 +194,7 @@ export default class SchemaPublish extends Command<typeof SchemaPublish> {
args: flags,
legacyFlagName: 'token',
env: 'HIVE_TOKEN',
message: ACCESS_TOKEN_MISSING,
});
const service = flags.service;
const url = flags.url;
Expand Down
2 changes: 2 additions & 0 deletions packages/libraries/cli/src/commands/whoami.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Flags } from '@oclif/core';
import Command from '../base-command';
import { graphql } from '../gql';
import { graphqlEndpoint } from '../helpers/config';
import { ACCESS_TOKEN_MISSING } from '../helpers/errors';

const myTokenInfoQuery = graphql(/* GraphQL */ `
query myTokenInfo {
Expand Down Expand Up @@ -74,6 +75,7 @@ export default class WhoAmI extends Command<typeof WhoAmI> {
legacyFlagName: 'token',
args: flags,
env: 'HIVE_TOKEN',
message: ACCESS_TOKEN_MISSING,
});

const result = await this.registryApi(registry, token)
Expand Down
1 change: 1 addition & 0 deletions packages/libraries/cli/src/helpers/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ACCESS_TOKEN_MISSING = `--registry.accessToken is required. For help generating an access token, see https://the-guild.dev/graphql/hive/docs/management/targets#registry-access-tokens`;

0 comments on commit 5a6e565

Please sign in to comment.