diff --git a/.changeset/perfect-files-yell.md b/.changeset/perfect-files-yell.md new file mode 100644 index 0000000000..3df31b0559 --- /dev/null +++ b/.changeset/perfect-files-yell.md @@ -0,0 +1,5 @@ +--- +'@graphql-hive/cli': patch +--- + +Print a detailed error when a command is executed without a hive access token diff --git a/packages/libraries/cli/src/commands/app/create.ts b/packages/libraries/cli/src/commands/app/create.ts index a53457a447..2179ab49c9 100644 --- a/packages/libraries/cli/src/commands/app/create.ts +++ b/packages/libraries/cli/src/commands/app/create.ts @@ -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 { static description = 'create an app deployment'; @@ -46,6 +47,7 @@ export default class AppCreate extends Command { key: 'registry.accessToken', args: flags, env: 'HIVE_TOKEN', + message: ACCESS_TOKEN_MISSING, }); const file: string = args.file; diff --git a/packages/libraries/cli/src/commands/app/publish.ts b/packages/libraries/cli/src/commands/app/publish.ts index fbc31e3b68..45a990be9a 100644 --- a/packages/libraries/cli/src/commands/app/publish.ts +++ b/packages/libraries/cli/src/commands/app/publish.ts @@ -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 { static description = 'publish an app deployment'; @@ -35,6 +36,7 @@ export default class AppPublish extends Command { key: 'registry.accessToken', args: flags, env: 'HIVE_TOKEN', + message: ACCESS_TOKEN_MISSING, }); const result = await this.registryApi(endpoint, accessToken).request({ diff --git a/packages/libraries/cli/src/commands/dev.ts b/packages/libraries/cli/src/commands/dev.ts index e7a56bbfd0..577f88e90f 100644 --- a/packages/libraries/cli/src/commands/dev.ts +++ b/packages/libraries/cli/src/commands/dev.ts @@ -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'; @@ -204,6 +205,7 @@ export default class Dev extends Command { legacyFlagName: 'token', args: flags, env: 'HIVE_TOKEN', + message: ACCESS_TOKEN_MISSING, }); void this.watch(flags.watchInterval, serviceInputs, services => @@ -249,6 +251,7 @@ export default class Dev extends Command { legacyFlagName: 'token', args: flags, env: 'HIVE_TOKEN', + message: ACCESS_TOKEN_MISSING, }); return this.compose({ diff --git a/packages/libraries/cli/src/commands/operations/check.ts b/packages/libraries/cli/src/commands/operations/check.ts index 466e923f35..97688eee60 100644 --- a/packages/libraries/cli/src/commands/operations/check.ts +++ b/packages/libraries/cli/src/commands/operations/check.ts @@ -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 */ ` @@ -95,6 +96,7 @@ export default class OperationsCheck extends Command { args: flags, legacyFlagName: 'token', env: 'HIVE_TOKEN', + message: ACCESS_TOKEN_MISSING, }); const graphqlTag = flags.graphqlTag; const globalGraphqlTag = flags.globalGraphqlTag; diff --git a/packages/libraries/cli/src/commands/schema/check.ts b/packages/libraries/cli/src/commands/schema/check.ts index dcb1af36c2..0a3af1ab52 100644 --- a/packages/libraries/cli/src/commands/schema/check.ts +++ b/packages/libraries/cli/src/commands/schema/check.ts @@ -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, @@ -169,6 +170,7 @@ export default class SchemaCheck extends Command { args: flags, legacyFlagName: 'token', env: 'HIVE_TOKEN', + message: ACCESS_TOKEN_MISSING, }); const sdl = await loadSchema(file); const git = await gitInfo(() => { diff --git a/packages/libraries/cli/src/commands/schema/delete.ts b/packages/libraries/cli/src/commands/schema/delete.ts index 61e6c5e5ba..62ebfb7347 100644 --- a/packages/libraries/cli/src/commands/schema/delete.ts +++ b/packages/libraries/cli/src/commands/schema/delete.ts @@ -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 */ ` @@ -110,6 +111,7 @@ export default class SchemaDelete extends Command { args: flags, legacyFlagName: 'token', env: 'HIVE_TOKEN', + message: ACCESS_TOKEN_MISSING, }); const result = await this.registryApi(endpoint, accessToken).request({ diff --git a/packages/libraries/cli/src/commands/schema/fetch.ts b/packages/libraries/cli/src/commands/schema/fetch.ts index a2e729d9ac..ff50c43ace 100644 --- a/packages/libraries/cli/src/commands/schema/fetch.ts +++ b/packages/libraries/cli/src/commands/schema/fetch.ts @@ -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( @@ -83,6 +84,7 @@ export default class SchemaFetch extends Command { args: flags, legacyFlagName: 'token', env: 'HIVE_TOKEN', + message: ACCESS_TOKEN_MISSING, }); const actionId: string = args.actionId; diff --git a/packages/libraries/cli/src/commands/schema/publish.ts b/packages/libraries/cli/src/commands/schema/publish.ts index 108f6260a0..a3603919e4 100644 --- a/packages/libraries/cli/src/commands/schema/publish.ts +++ b/packages/libraries/cli/src/commands/schema/publish.ts @@ -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'; @@ -193,6 +194,7 @@ export default class SchemaPublish extends Command { args: flags, legacyFlagName: 'token', env: 'HIVE_TOKEN', + message: ACCESS_TOKEN_MISSING, }); const service = flags.service; const url = flags.url; diff --git a/packages/libraries/cli/src/commands/whoami.ts b/packages/libraries/cli/src/commands/whoami.ts index 3ada6a5ed0..939f6b0a65 100644 --- a/packages/libraries/cli/src/commands/whoami.ts +++ b/packages/libraries/cli/src/commands/whoami.ts @@ -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 { @@ -74,6 +75,7 @@ export default class WhoAmI extends Command { legacyFlagName: 'token', args: flags, env: 'HIVE_TOKEN', + message: ACCESS_TOKEN_MISSING, }); const result = await this.registryApi(registry, token) diff --git a/packages/libraries/cli/src/helpers/errors.ts b/packages/libraries/cli/src/helpers/errors.ts new file mode 100644 index 0000000000..964839fe3a --- /dev/null +++ b/packages/libraries/cli/src/helpers/errors.ts @@ -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`;