Skip to content

Commit 07b6041

Browse files
authored
Merge pull request #1358 from apollographql/mkoneval/AP-512/service-list-cli
service:list in CLI
2 parents 481e109 + eaad228 commit 07b6041

9 files changed

Lines changed: 542 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- `apollo`
66
- Relax graphql version, resolve missing types "Boolean", "String" [#1355](https://github.com/apollographql/apollo-tooling/pull/1355)
7+
- Add `service:list` and tests [#1358](https://github.com/apollographql/apollo-tooling/pull/1358)
78
- `apollo-codegen-core`
89
- <First `apollo-codegen-core` related entry goes here>
910
- `apollo-codegen-flow`

packages/apollo-language-server/src/engine/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { SCHEMA_TAGS_AND_FIELD_STATS } from "./operations/schemaTagsAndFieldStat
88
import { UPLOAD_AND_COMPOSE_PARTIAL_SCHEMA } from "./operations/uploadAndComposePartialSchema";
99
import { CHECK_PARTIAL_SCHEMA } from "./operations/checkPartialSchema";
1010
import { REMOVE_SERVICE_AND_COMPOSE } from "./operations/removeServiceAndCompose";
11+
import { LIST_SERVICES } from "./operations/listServices";
1112
import {
13+
ListServices,
14+
ListServicesVariables,
1215
CheckSchema,
1316
CheckSchemaVariables,
1417
UploadSchema,
@@ -77,6 +80,29 @@ export class ApolloEngineClient extends GraphQLDataSource {
7780
] = require("../../package.json").version;
7881
}
7982

83+
public async listServices(variables: ListServicesVariables) {
84+
return this.execute<ListServices>({
85+
query: LIST_SERVICES,
86+
variables
87+
}).then(({ data, errors }) => {
88+
// use error logger
89+
if (errors) {
90+
throw new Error(errors.map(error => error.message).join("\n"));
91+
}
92+
93+
if (data && !data.service) {
94+
throw new Error(
95+
noServiceError(getServiceFromKey(this.engineKey), this.baseURL)
96+
);
97+
}
98+
99+
if (!(data && data.service)) {
100+
throw new Error("Error in request from Engine");
101+
}
102+
return data.service;
103+
});
104+
}
105+
80106
public async checkSchema(variables: CheckSchemaVariables) {
81107
return this.execute<CheckSchema>({
82108
query: CHECK_SCHEMA,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import gql from "graphql-tag";
2+
3+
export const LIST_SERVICES = gql`
4+
query ListServices($id: ID!, $graphVariant: String!) {
5+
service(id: $id) {
6+
implementingServices(graphVariant: $graphVariant) {
7+
__typename
8+
... on FederatedImplementingServices {
9+
services {
10+
graphID
11+
graphVariant
12+
name
13+
url
14+
updatedAt
15+
}
16+
}
17+
}
18+
}
19+
}
20+
`;

packages/apollo-language-server/src/graphqlTypes.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,72 @@ export interface CheckSchemaVariables {
194194
/* eslint-disable */
195195
// This file was automatically generated and should not be edited.
196196

197+
// ====================================================
198+
// GraphQL query operation: ListServices
199+
// ====================================================
200+
201+
export interface ListServices_service_implementingServices_NonFederatedImplementingService {
202+
__typename: "NonFederatedImplementingService";
203+
}
204+
205+
export interface ListServices_service_implementingServices_FederatedImplementingServices_services {
206+
__typename: "FederatedImplementingService";
207+
/**
208+
* Identifies which graph this implementing service belongs to.
209+
* Formerly known as "service_id"
210+
*/
211+
graphID: string;
212+
/**
213+
* Specifies which variant of a graph this implementing service belongs to".
214+
* Formerly known as "tag"
215+
*/
216+
graphVariant: string;
217+
/**
218+
* Name of the implementing service
219+
*/
220+
name: string;
221+
/**
222+
* URL of the graphql endpoint of the implementing service
223+
*/
224+
url: string | null;
225+
/**
226+
* Timestamp for when this implementing service was updated
227+
*/
228+
updatedAt: any;
229+
}
230+
231+
export interface ListServices_service_implementingServices_FederatedImplementingServices {
232+
__typename: "FederatedImplementingServices";
233+
services: ListServices_service_implementingServices_FederatedImplementingServices_services[];
234+
}
235+
236+
export type ListServices_service_implementingServices = ListServices_service_implementingServices_NonFederatedImplementingService | ListServices_service_implementingServices_FederatedImplementingServices;
237+
238+
export interface ListServices_service {
239+
__typename: "Service";
240+
/**
241+
* Implementing services that comprise a graph.
242+
* Set includeDeleted to see deleted implementing services
243+
*/
244+
implementingServices: ListServices_service_implementingServices | null;
245+
}
246+
247+
export interface ListServices {
248+
/**
249+
* Service by ID
250+
*/
251+
service: ListServices_service | null;
252+
}
253+
254+
export interface ListServicesVariables {
255+
id: string;
256+
graphVariant: string;
257+
}
258+
259+
/* tslint:disable */
260+
/* eslint-disable */
261+
// This file was automatically generated and should not be edited.
262+
197263
// ====================================================
198264
// GraphQL mutation operation: RegisterOperations
199265
// ====================================================
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`service:list integration should display non federated message for a non federated service vanilla 1`] = `
4+
"Loading Apollo Project [started]
5+
Loading Apollo Project [completed]
6+
Fetching list of services for graph engine [started]
7+
Fetching list of services for graph engine [completed]
8+
9+
There are no services on this federated graph
10+
"
11+
`;
12+
13+
exports[`service:list integration should list services correctly for a federated service vanilla 1`] = `
14+
"Loading Apollo Project [started]
15+
Loading Apollo Project [completed]
16+
Fetching list of services for graph engine [started]
17+
Fetching list of services for graph engine [completed]
18+
19+
accounts http://localhost:4001/graphql 13 May 2019 (a month ago)
20+
inventory http://localhost:4002/graphql 16 May 2019 (a month ago)
21+
products http://localhost:4003/graphql 16 May 2019 (a month ago)
22+
reviews http://localhost:4004/graphql 16 May 2019 (a month ago)
23+
24+
View full details at: https://engine-staging.apollographql.com/graph/engine/service-list
25+
"
26+
`;

packages/apollo/src/commands/service/__tests__/check.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ let mockedConsoleLogOriginal: Console["log"] | null = null;
5050
*/
5151
let mockedConsoleLogValues: string[] | null = null;
5252

53+
// TODO: the following two functions are identical to the ones found in list.test.ts
54+
// we are choosing to duplicate them for now, because with a shared helper function,
55+
// jest overwrites console log output as the tests are run in parallel
56+
5357
/**
5458
* Mock and capture `console.log` and `stdout.write`s. Return them in that order as a single string.
5559
*

0 commit comments

Comments
 (0)