Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update "no service found to link..." error #1847

Merged
merged 3 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 3 additions & 6 deletions packages/apollo/src/commands/service/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import { GraphQLSchema } from "graphql";
import sortBy from "lodash.sortby";
import { table } from "table";
import moment from "moment";
import {
ApolloConfig,
isServiceProject,
DefaultEngineConfig
} from "apollo-language-server";
import { ApolloConfig, DefaultEngineConfig } from "apollo-language-server";
import chalk from "chalk";
import {
ListServices_service_implementingServices,
ListServices_service_implementingServices_FederatedImplementingServices_services
} from "apollo-language-server/lib/graphqlTypes";
import { graphUndefinedError } from "../../utils/errors";

interface TasksOutput {
config: ApolloConfig;
Expand Down Expand Up @@ -114,7 +111,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://go.apollo.dev/t/config"
].join(" ");
export const graphUndefinedError = new CLIError(errorMessage);