Skip to content

Commit 438e9d1

Browse files
author
James Baxley
committed
support updated mutation for pushing a partial service
1 parent bddcb43 commit 438e9d1

8 files changed

Lines changed: 196 additions & 31 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ export class GraphQLDataSource<TContext = any> {
104104
}
105105

106106
private onErrorLink() {
107-
return onError(({ graphQLErrors, networkError }) => {
107+
return onError(({ graphQLErrors, networkError, operation }) => {
108+
const { result, response } = operation.getContext();
108109
if (graphQLErrors) {
109110
graphQLErrors.map(graphqlError =>
110111
console.error(`[GraphQL error]: ${graphqlError.message}`)
@@ -114,6 +115,10 @@ export class GraphQLDataSource<TContext = any> {
114115
if (networkError) {
115116
console.log(`[Network Error]: ${networkError}`);
116117
}
118+
119+
if (response && response.status >= 400) {
120+
console.log(`[Network Error] ${response.bodyText}`);
121+
}
117122
});
118123
}
119124
}

packages/apollo-language-server/src/engine/operations/checkPartialSchema.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@ export const CHECK_PARTIAL_SCHEMA = gql`
1313
implementingServiceName: $implementingServiceName
1414
partialSchema: $partialSchema
1515
) {
16-
schemaHash
16+
compositionConfig {
17+
schemaHash
18+
}
19+
errors {
20+
message
21+
}
22+
warnings {
23+
message
24+
}
25+
didUpdateGateway: updatedGateway
1726
}
1827
}
1928
}

packages/apollo-language-server/src/engine/operations/checkSchema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const CHECK_SCHEMA = gql`
1919
) {
2020
targetUrl
2121
diffToPrevious {
22-
type
22+
type: severity
2323
affectedClients {
2424
__typename
2525
}
@@ -28,7 +28,7 @@ export const CHECK_SCHEMA = gql`
2828
}
2929
numberOfCheckedOperations
3030
changes {
31-
type
31+
type: severity
3232
code
3333
description
3434
}

packages/apollo-language-server/src/engine/operations/uploadAndComposePartialSchema.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,28 @@ export const UPLOAD_AND_COMPOSE_PARTIAL_SCHEMA = gql`
66
$graphVariant: String!
77
$name: String!
88
$url: String!
9-
$sha: String!
9+
$revision: String!
1010
$activePartialSchema: PartialSchemaInput!
1111
) {
1212
service(id: $id) {
1313
upsertImplementingServiceAndTriggerComposition(
1414
name: $name
1515
url: $url
16-
sha: $sha
16+
revision: $revision
1717
activePartialSchema: $activePartialSchema
1818
graphVariant: $graphVariant
1919
) {
20-
schemaHash
20+
compositionConfig {
21+
schemaHash
22+
}
23+
errors {
24+
message
25+
}
26+
warnings {
27+
message
28+
}
29+
didUpdateGateway: updatedGateway
30+
serviceWasCreated: wasCreated
2131
}
2232
}
2333
}

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

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,50 @@
66
// GraphQL mutation operation: CheckPartialSchema
77
// ====================================================
88

9-
export interface CheckPartialSchema_service_validatePartialSchemaOfImplementingServiceAgainstGraph {
10-
__typename: "CompositionResult";
9+
export interface CheckPartialSchema_service_validatePartialSchemaOfImplementingServiceAgainstGraph_compositionConfig {
10+
__typename: "CompositionConfig";
1111
/**
1212
* Hash of the composed schema
1313
*/
1414
schemaHash: string;
1515
}
1616

17+
export interface CheckPartialSchema_service_validatePartialSchemaOfImplementingServiceAgainstGraph_errors {
18+
__typename: "SchemaCompositionError";
19+
message: string;
20+
}
21+
22+
export interface CheckPartialSchema_service_validatePartialSchemaOfImplementingServiceAgainstGraph_warnings {
23+
__typename: "SchemaCompositionWarning";
24+
message: string;
25+
}
26+
27+
export interface CheckPartialSchema_service_validatePartialSchemaOfImplementingServiceAgainstGraph {
28+
__typename: "CompositionResult";
29+
/**
30+
* The produced composition config. Will be null if there are any errors
31+
*/
32+
compositionConfig: CheckPartialSchema_service_validatePartialSchemaOfImplementingServiceAgainstGraph_compositionConfig | null;
33+
/**
34+
* List of errors during composition. Errors mean that Apollo was unable to compose the
35+
* graph's implementing services into a GraphQL schema. This partial schema should not be
36+
* published to the implementing service if there were any errors encountered
37+
*/
38+
errors: (CheckPartialSchema_service_validatePartialSchemaOfImplementingServiceAgainstGraph_errors | null)[];
39+
/**
40+
* List of warnings encountered during composing implementing services into a complete schema.
41+
* Though a schema was composed for the graph with the proposed partial schema,
42+
* these warnings may indicate undesired behavior or lost information. We recommend that no service
43+
* is pushed with warnings that are not fully understood. Pushing an implementing service with warnings
44+
* in its composition result will result in updating the composition config.
45+
*/
46+
warnings: (CheckPartialSchema_service_validatePartialSchemaOfImplementingServiceAgainstGraph_warnings | null)[];
47+
/**
48+
* Whether the gateway link was updated.
49+
*/
50+
didUpdateGateway: boolean;
51+
}
52+
1753
export interface CheckPartialSchema_service {
1854
__typename: "ServiceMutation";
1955
/**
@@ -60,7 +96,7 @@ export interface CheckSchema_service_checkSchema_diffToPrevious_changes {
6096
/**
6197
* Indication of the success of the overall change, either failure, warning, or notice.
6298
*/
63-
type: ChangeType;
99+
type: ChangeSeverity;
64100
/**
65101
* Indication of the kind of target and action of the change, e.g. 'TYPE_REMOVED'.
66102
*/
@@ -88,7 +124,10 @@ export interface CheckSchema_service_checkSchema_diffToPrevious_validationConfig
88124

89125
export interface CheckSchema_service_checkSchema_diffToPrevious {
90126
__typename: "SchemaDiff";
91-
type: ChangeType;
127+
/**
128+
* Indication of the success of the change, either failure, warning, or notice.
129+
*/
130+
type: ChangeSeverity;
92131
/**
93132
* Clients affected by all changes in diff
94133
*/
@@ -296,14 +335,54 @@ export interface SchemaTagsAndFieldStatsVariables {
296335
// GraphQL mutation operation: UploadAndComposePartialSchema
297336
// ====================================================
298337

299-
export interface UploadAndComposePartialSchema_service_upsertImplementingServiceAndTriggerComposition {
300-
__typename: "CompositionResult";
338+
export interface UploadAndComposePartialSchema_service_upsertImplementingServiceAndTriggerComposition_compositionConfig {
339+
__typename: "CompositionConfig";
301340
/**
302341
* Hash of the composed schema
303342
*/
304343
schemaHash: string;
305344
}
306345

346+
export interface UploadAndComposePartialSchema_service_upsertImplementingServiceAndTriggerComposition_errors {
347+
__typename: "SchemaCompositionError";
348+
message: string;
349+
}
350+
351+
export interface UploadAndComposePartialSchema_service_upsertImplementingServiceAndTriggerComposition_warnings {
352+
__typename: "SchemaCompositionWarning";
353+
message: string;
354+
}
355+
356+
export interface UploadAndComposePartialSchema_service_upsertImplementingServiceAndTriggerComposition {
357+
__typename: "CompositionAndUpsertResult";
358+
/**
359+
* The produced composition config. Will be null if there are any errors
360+
*/
361+
compositionConfig: UploadAndComposePartialSchema_service_upsertImplementingServiceAndTriggerComposition_compositionConfig | null;
362+
/**
363+
* List of errors during composition. Errors mean that Apollo was unable to compose the
364+
* graph's implementing services into a GraphQL schema. This partial schema should not be
365+
* published to the implementing service if there were any errors encountered
366+
*/
367+
errors: (UploadAndComposePartialSchema_service_upsertImplementingServiceAndTriggerComposition_errors | null)[];
368+
/**
369+
* List of warnings encountered during composing implementing services into a complete schema.
370+
* Though a schema was composed for the graph with the proposed partial schema,
371+
* these warnings may indicate undesired behavior or lost information. We recommend that no service
372+
* is pushed with warnings that are not fully understood. Pushing an implementing service with warnings
373+
* in its composition result will result in updating the composition config.
374+
*/
375+
warnings: (UploadAndComposePartialSchema_service_upsertImplementingServiceAndTriggerComposition_warnings | null)[];
376+
/**
377+
* Whether the gateway link was updated.
378+
*/
379+
didUpdateGateway: boolean;
380+
/**
381+
* Whether an implementingService was created as part of this mutation
382+
*/
383+
serviceWasCreated: boolean;
384+
}
385+
307386
export interface UploadAndComposePartialSchema_service {
308387
__typename: "ServiceMutation";
309388
/**
@@ -328,7 +407,7 @@ export interface UploadAndComposePartialSchemaVariables {
328407
graphVariant: string;
329408
name: string;
330409
url: string;
331-
sha: string;
410+
revision: string;
332411
activePartialSchema: PartialSchemaInput;
333412
}
334413

@@ -1364,7 +1443,7 @@ export interface IntrospectionTypeRef {
13641443
// START Enums and Input Objects
13651444
//==============================================================
13661445

1367-
export enum ChangeType {
1446+
export enum ChangeSeverity {
13681447
FAILURE = "FAILURE",
13691448
NOTICE = "NOTICE",
13701449
WARNING = "WARNING",

packages/apollo-language-server/src/providers/federation-info/endpoint.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export class EndpointFederationInfoProvider
2424
query getFederationInfo {
2525
_service {
2626
sdl
27-
name
28-
url
2927
}
3028
}
3129
`;

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { validateHistoricParams } from "../../utils";
88
import {
99
CheckSchema_service_checkSchema,
1010
CheckSchema_service_checkSchema_diffToPrevious_changes as Change,
11-
ChangeType
11+
ChangeSeverity as ChangeType
1212
} from "apollo-language-server/lib/graphqlTypes";
1313
import { ApolloConfig, GraphQLServiceProject } from "apollo-language-server";
1414
import moment from "moment";
@@ -263,7 +263,11 @@ export default class ServiceCheck extends ProjectCommand {
263263
* name: implementing service name inside of the graph
264264
* sha: git commit hash/docker id. placeholder for now
265265
*/
266-
const { schemaHash } = await project.engine.checkPartialSchema({
266+
const {
267+
errors,
268+
warnings,
269+
compositionConfig
270+
} = await project.engine.checkPartialSchema({
267271
id: config.name,
268272
graphVariant: config.name,
269273
implementingServiceName: info.name,
@@ -272,7 +276,14 @@ export default class ServiceCheck extends ProjectCommand {
272276
}
273277
});
274278

275-
console.log({ schemaHash });
279+
if (errors.length) {
280+
this.error(errors.join("\n"));
281+
return;
282+
}
283+
if (warnings.length) {
284+
this.warn(warnings.join("\n"));
285+
}
286+
276287
return;
277288
}
278289

0 commit comments

Comments
 (0)