Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/apollo/src/commands/client/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { relative } from "path";
import { graphqlTypes } from "apollo-language-server";
import chalk from "chalk";
import envCi from "env-ci";
import { graphUndefinedError } from "../../utils/errors";

const { ValidationErrorType } = graphqlTypes;
type ValidationResult = graphqlTypes.ValidateOperations_service_validateOperations_validationResults;
Expand Down Expand Up @@ -41,9 +42,7 @@ export default class ClientCheck extends ClientCommand {
title: "Checking client compatibility with service",
task: async ctx => {
if (!config.name) {
throw new Error(
"No service found to link to Apollo Graph Manager. Graph Manager is required for this command."
);
throw graphUndefinedError;
}
ctx.gitContext = await gitInfo(this.log);

Expand Down
5 changes: 2 additions & 3 deletions packages/apollo/src/commands/client/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ApolloConfig,
graphqlTypes
} from "apollo-language-server";
import { graphUndefinedError } from "../../utils/errors";

export default class ClientPush extends ClientCommand {
static description =
Expand Down Expand Up @@ -60,9 +61,7 @@ export default class ClientPush extends ClientCommand {
title: "Pushing operations to operation registry",
task: async (_, task) => {
if (!config.name) {
throw new Error(
"No service found to link to Apollo Graph Manager. Graph Manager is required for this command."
);
throw graphUndefinedError;
}

const operationManifest = getOperationManifestFromProject(
Expand Down
3 changes: 2 additions & 1 deletion packages/apollo/src/commands/service/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ApolloConfig, isServiceProject } from "apollo-language-server";
import moment from "moment";
import sortBy from "lodash.sortby";
import { isNotNullOrUndefined } from "apollo-env";
import { graphUndefinedError } from "../../utils/errors";

const formatChange = (change: Change) => {
let color = (x: string): string => x;
Expand Down Expand Up @@ -304,7 +305,7 @@ export default class ServiceCheck extends ProjectCommand {
const serviceName: string | undefined = flags.serviceName;

if (!graphID) {
throw new Error("No service found to link to Apollo Graph Manager");
throw graphUndefinedError;
}

// Add some fields to output that are required for producing
Expand Down
3 changes: 2 additions & 1 deletion packages/apollo/src/commands/service/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import cli from "cli-ux";
import { flags } from "@oclif/command";

import { ProjectCommand } from "../../Command";
import { graphUndefinedError } from "../../utils/errors";

export default class ServiceDelete extends ProjectCommand {
static description =
Expand Down Expand Up @@ -52,7 +53,7 @@ export default class ServiceDelete extends ProjectCommand {
title: "Removing service from Apollo Graph Manager",
task: async () => {
if (!config.name) {
throw new Error("No service found to link to Apollo Graph Manager");
throw graphUndefinedError;
}

if (flags.federated) {
Expand Down
4 changes: 3 additions & 1 deletion packages/apollo/src/commands/service/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
ListServices_service_implementingServices,
ListServices_service_implementingServices_FederatedImplementingServices_services
} from "apollo-language-server/lib/graphqlTypes";
import { CLIError } from "@oclif/errors";
Comment thread
JakeDawkins marked this conversation as resolved.
Outdated
import { graphUndefinedError } from "../../utils/errors";

interface TasksOutput {
config: ApolloConfig;
Expand Down Expand Up @@ -114,7 +116,7 @@ export default class ServiceList extends ProjectCommand {
graphVariant = flags.tag || config.tag || "current";

if (!graphID) {
throw new Error("No service found to link to Apollo Graph Manager");
throw graphUndefinedError;
}

return [
Expand Down
3 changes: 2 additions & 1 deletion packages/apollo/src/commands/service/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ProjectCommand } from "../../Command";
import { UploadSchemaVariables } from "apollo-language-server/lib/graphqlTypes";
import { GraphQLServiceProject } from "apollo-language-server";
import chalk from "chalk";
import { graphUndefinedError } from "../../utils/errors";

export default class ServicePush extends ProjectCommand {
static aliases = ["schema:publish"];
Expand Down Expand Up @@ -51,7 +52,7 @@ export default class ServicePush extends ProjectCommand {
title: "Uploading service to Apollo Graph Manager",
task: async () => {
if (!config.name) {
throw new Error("No service found to link to Apollo Graph Manager");
throw graphUndefinedError;
}

if (flags.federated) {
Expand Down
9 changes: 9 additions & 0 deletions packages/apollo/src/utils/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { CLIError } from "@oclif/errors";

const errorMessage = [
"No graph (i.e. service) found to link to Apollo Graph Manager.",
"In order to run this command, please provide a graph ID using the 'apollo.config.js' file.",
"\n\nFor more information on configuring the Apollo CLI, please go to",
"https://www.apollographql.com/docs/devtools/apollo-config/"
Comment thread
zionts marked this conversation as resolved.
Outdated
].join(" ");
export const graphUndefinedError = new CLIError(errorMessage);