Skip to content

Commit 2a9a75d

Browse files
AP-490: Finalize federated service check and add integration tests (#1308)
AP-490: Finalize federated service check and add integration tests
2 parents f5b980e + a12eab0 commit 2a9a75d

7 files changed

Lines changed: 1057 additions & 196 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## Upcoming
44

55
- `apollo`
6-
- <First `apollo` related entry goes here>
6+
- Add integration tests to `service:check` [#1308](https://github.com/apollographql/apollo-tooling/pull/1308)
7+
- Add support for federated service to `service:check` [#1308](https://github.com/apollographql/apollo-tooling/pull/1308)
78
- `apollo-codegen-core`
89
- <First `apollo-codegen-core` related entry goes here>
910
- `apollo-codegen-flow`

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"memfs": "2.15.4",
8383
"nock": "10.0.6",
8484
"prettier": "1.17.1",
85+
"stdout-stderr": "^0.1.9",
8586
"symlink-dir": "3.1.0",
8687
"ts-jest": "24.0.2",
8788
"ts-node": "8.2.0",

packages/apollo/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,11 @@ node --inspect-brk=9002 packages/apollo/bin/run <command>
752752
753753
If you're using VS Code, you can run the included "Attach to CLI Debugger" launch task and debug right from VS Code! Otherwise, you may use the (Chrome inspector)[https://nodejs.org/en/docs/guides/debugging-getting-started/] or other Node debugger of your choice.
754754
755+
## Regenerating Mocked Network Data
756+
757+
Some integration tests rely on mocked server data (service:check for example). Mock data is generated by making real network requests and recording those requests with [`nock`'s recording feature](https://github.com/nock/nock#recording). Stop mocking network calls and add `nock.recorder.rec()` before network calls are made. For `service:check`, change `apiKey` to a real engine API key. Then run the tests and nock will output code to mock requests to the console. You can (and probably should) pare down the request to be less brittle (by only checking for an operation name, for example). See [`src/commands/service/__tests__/check.test.ts`](./packages/apollo/src/commands/service/__tests__/check.test.ts) for an example of how a mocked network request will look.
758+
759+
755760
## Publishing
756761
757762
- Make sure the `CHANGELOG.md` is updated with all changes committed since the last release. Make sure the versions for each package to update are correct, and there's a blank `Upcoming` section for future work.

packages/apollo/src/Command.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,17 @@ export abstract class ProjectCommand extends Command {
224224
}
225225

226226
const tasks = await generateTasks(ctx);
227-
return new Listr(
228-
[...this.tasks, ...tasks],
229-
typeof options === "function" ? options(ctx) : options
230-
).run();
227+
return new Listr([...this.tasks, ...tasks], {
228+
// Use the `verbose` renderer for tests. We need this for two reasons:
229+
// 1. We don't want to show a spinner in tests
230+
// 2. We want to see individual changes to titles and output lines; this is accomplished with the
231+
// verbose renderer. Note that this _must_ be override-able because some functions require the
232+
// `silent` renderer.
233+
...(process.env.NODE_ENV === "test" && { renderer: "verbose" }),
234+
...(options && typeof options === "function" ? options(ctx) : options),
235+
// @ts-ignore This option is added by https://github.com/SamVerschueren/listr-verbose-renderer#options
236+
dateFormat: false
237+
}).run();
231238
}
232239
async catch(err) {
233240
// handle any error from the command
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`service:check formatHumanReadable should have correct output with breaking and non-breaking changes 1`] = `
4+
"
5+
FAIL ARG_REMOVED \`ServiceMutation.uploadSchema\` arg \`gitContext\` was removed
6+
FAIL ARG_REMOVED \`ServiceMutation.uploadSchema\` arg \`schema\` was removed
7+
FAIL ARG_REMOVED \`ServiceMutation.uploadSchema\` arg \`tag\` was removed
8+
FAIL FIELD_CHANGED_TYPE \`Change.argNode\` changed type from \`NamedIntrospectionArg\` to \`NamedIntrospectionValue\`
9+
FAIL FIELD_REMOVED \`Change.affectedClients\` was removed
10+
FAIL FIELD_REMOVED \`NamedIntrospectionValue.printedType\` was removed
11+
FAIL TYPE_REMOVED \`NamedIntrospectionArg\` removed
12+
13+
PASS ARG_REMOVED \`ServiceMutation.registerOperations\` arg \`manifestVersion\` was removed
14+
PASS ARG_REMOVED \`ServiceMutation.uploadSchema\` arg \`historicParameters\` was removed
15+
PASS FIELD_ADDED \`Service.schemaNotificationChannels\` was added
16+
PASS FIELD_ADDED \`ServiceMutation.deregisterSchemaNotificationChannel\` was added
17+
PASS FIELD_ADDED \`ServiceMutation.registerSchemaNotificationChannel\` was added
18+
PASS FIELD_DEPRECATION_REMOVED \`AffectedClient.clientId\` is no longer deprecated
19+
PASS FIELD_DEPRECATION_REMOVED \`Change.description\` is no longer deprecated
20+
PASS FIELD_REMOVED \`AffectedClient.clientReferenceId\` was removed
21+
PASS FIELD_REMOVED \`Change.affectedClientIdVersionPairs\` was removed
22+
PASS FIELD_REMOVED \`Change.affectedClientReferenceIds\` was removed
23+
PASS FIELD_REMOVED \`SchemaDiff.numberOfCheckedOperations\` was removed
24+
25+
View full details at: https://engine-dev.apollographql.com/service/engine/checks?schemaTag=Detached%3A%20d664f715645c5f0bb5ad4f2260cd6cb8d19bbc68&schemaTagId=f9f68e7e-1b5f-4eab-a3da-1fd8cd681111&from=2019-03-26T22%3A25%3A12.887Z"
26+
`;
27+
28+
exports[`service:check formatHumanReadable should have correct output with only breaking changes 1`] = `
29+
"
30+
FAIL ARG_REMOVED \`ServiceMutation.uploadSchema\` arg \`gitContext\` was removed
31+
FAIL ARG_REMOVED \`ServiceMutation.uploadSchema\` arg \`schema\` was removed
32+
FAIL ARG_REMOVED \`ServiceMutation.uploadSchema\` arg \`tag\` was removed
33+
FAIL FIELD_CHANGED_TYPE \`Change.argNode\` changed type from \`NamedIntrospectionArg\` to \`NamedIntrospectionValue\`
34+
FAIL FIELD_REMOVED \`Change.affectedClients\` was removed
35+
FAIL FIELD_REMOVED \`NamedIntrospectionValue.printedType\` was removed
36+
FAIL TYPE_REMOVED \`NamedIntrospectionArg\` removed
37+
38+
View full details at: https://engine-dev.apollographql.com/service/engine/checks?schemaTag=Detached%3A%20d664f715645c5f0bb5ad4f2260cd6cb8d19bbc68&schemaTagId=f9f68e7e-1b5f-4eab-a3da-1fd8cd681111&from=2019-03-26T22%3A25%3A12.887Z"
39+
`;
40+
41+
exports[`service:check formatHumanReadable should have correct output with only non-breaking changes 1`] = `
42+
"
43+
No changes present between schemas
44+
45+
View full details at: https://engine-dev.apollographql.com/service/engine/checks?schemaTag=Detached%3A%20d664f715645c5f0bb5ad4f2260cd6cb8d19bbc68&schemaTagId=f9f68e7e-1b5f-4eab-a3da-1fd8cd681111&from=2019-03-26T22%3A25%3A12.887Z"
46+
`;
47+
48+
exports[`service:check integration federated should report composition errors correctly vanilla 1`] = `
49+
"Loading Apollo Project [started]
50+
Loading Apollo Project [completed]
51+
Validate graph composition for service accounts on graph engine [started]
52+
→ Fetching local service's partial schema
53+
→ Attempting to compose graph with accounts service's partial schema
54+
Found 3 graph composition errors for service accounts on graph engine [title changed]
55+
Found 3 graph composition errors for service accounts on graph engine [failed]
56+
→ Federated service composition was unsuccessful. Please see the reasons below.
57+
58+
Service Field Message
59+
──────── ─────── ────────────────────────────────────────────────────────────────────────────────────────
60+
reviews User.id marked @external but it does not have a matching field on on the base service (accounts)
61+
reviews User A @key selects id, but User.id could not be found
62+
accounts User A @key selects id, but User.id could not be found
63+
"
64+
`;
65+
66+
exports[`service:check integration federated should report composition success correctly vanilla 1`] = `
67+
"Loading Apollo Project [started]
68+
Loading Apollo Project [completed]
69+
Validate graph composition for service accounts on graph engine [started]
70+
→ Fetching local service's partial schema
71+
→ Attempting to compose graph with accounts service's partial schema
72+
Found 0 graph composition errors for service accounts on graph engine [title changed]
73+
Found 0 graph composition errors for service accounts on graph engine [completed]
74+
Validating composed schema against tag master on graph engine [started]
75+
→ Validating schema
76+
Validated composed schema against tag master on graph engine [title changed]
77+
Validated composed schema against tag master on graph engine [completed]
78+
Comparing schema changes [started]
79+
Compared 1 schema change against 0 operations over the last 548 days [title changed]
80+
Compared 1 schema change against 0 operations over the last 548 days [completed]
81+
Reporting result [started]
82+
Found 0 breaking changes and 1 compatible change [title changed]
83+
Found 0 breaking changes and 1 compatible change [completed]
84+
85+
PASS ARG_CHANGED_TYPE \`Query.launches\` argument \`after\` has changed type from \`String\` to \`String!\`
86+
87+
View full details at: https://engine-staging.apollographql.com/service/justin-fullstack-tutorial/check/3acd7765-61b2-4f1a-9227-8b288e42bfdc
88+
"
89+
`;
90+
91+
exports[`service:check integration non-federated should report traffic errors correctly --json 1`] = `
92+
"{
93+
\\"targetUrl\\": \\"https://engine-staging.apollographql.com/service/justin-fullstack-tutorial/check/3acd7765-61b2-4f1a-9227-8b288e42bfdc\\",
94+
\\"changes\\": [
95+
{
96+
\\"severity\\": \\"FAILURE\\",
97+
\\"code\\": \\"ARG_CHANGED_TYPE\\",
98+
\\"description\\": \\"\`Query.launches\` argument \`after\` has changed type from \`String\` to \`String!\`\\"
99+
}
100+
],
101+
\\"validationConfig\\": {
102+
\\"from\\": \\"-47347200\\",
103+
\\"to\\": \\"-0\\",
104+
\\"queryCountThreshold\\": 1,
105+
\\"queryCountThresholdPercentage\\": 0
106+
}
107+
}
108+
"
109+
`;
110+
111+
exports[`service:check integration non-federated should report traffic errors correctly --markdown 1`] = `
112+
"
113+
### Apollo Service Check
114+
🔄 Validated your local schema against schema tag \`master\` on graph \`engine\`.
115+
🔢 Compared **1 schema change** against **0 operations** seen over the **last 548 days**.
116+
❌ Found **1 breaking change** that would affect **0 operations** across **0 clients**
117+
118+
🔗 [View your service check details](https://engine-staging.apollographql.com/service/justin-fullstack-tutorial/check/3acd7765-61b2-4f1a-9227-8b288e42bfdc).
119+
120+
"
121+
`;
122+
123+
exports[`service:check integration non-federated should report traffic errors correctly vanilla 1`] = `
124+
"Loading Apollo Project [started]
125+
Loading Apollo Project [completed]
126+
Validating schema against tag master on graph engine [started]
127+
→ Resolving schema
128+
→ Validating schema
129+
Validated schema against tag master on graph engine [title changed]
130+
Validated schema against tag master on graph engine [completed]
131+
Comparing schema changes [started]
132+
Compared 1 schema change against 0 operations over the last 548 days [title changed]
133+
Compared 1 schema change against 0 operations over the last 548 days [completed]
134+
Reporting result [started]
135+
Found 1 breaking change and 0 compatible changes [title changed]
136+
Found 1 breaking change and 0 compatible changes [failed]
137+
→ breaking changes found
138+
139+
FAIL ARG_CHANGED_TYPE \`Query.launches\` argument \`after\` has changed type from \`String\` to \`String!\`
140+
141+
View full details at: https://engine-staging.apollographql.com/service/justin-fullstack-tutorial/check/3acd7765-61b2-4f1a-9227-8b288e42bfdc
142+
"
143+
`;
144+
145+
exports[`service:check integration non-federated should report traffic non-errors correctly --json 1`] = `
146+
"{
147+
\\"targetUrl\\": \\"https://engine-staging.apollographql.com/service/justin-fullstack-tutorial/check/3acd7765-61b2-4f1a-9227-8b288e42bfdc\\",
148+
\\"changes\\": [
149+
{
150+
\\"severity\\": \\"NOTICE\\",
151+
\\"code\\": \\"ARG_CHANGED_TYPE\\",
152+
\\"description\\": \\"\`Query.launches\` argument \`after\` has changed type from \`String\` to \`String!\`\\"
153+
}
154+
],
155+
\\"validationConfig\\": {
156+
\\"from\\": \\"-47347200\\",
157+
\\"to\\": \\"-0\\",
158+
\\"queryCountThreshold\\": 1,
159+
\\"queryCountThresholdPercentage\\": 0
160+
}
161+
}
162+
"
163+
`;
164+
165+
exports[`service:check integration non-federated should report traffic non-errors correctly --markdown 1`] = `
166+
"
167+
### Apollo Service Check
168+
🔄 Validated your local schema against schema tag \`master\` on graph \`engine\`.
169+
🔢 Compared **1 schema change** against **0 operations** seen over the **last 548 days**.
170+
✅ Found **no breaking changes**.
171+
172+
🔗 [View your service check details](https://engine-staging.apollographql.com/service/justin-fullstack-tutorial/check/3acd7765-61b2-4f1a-9227-8b288e42bfdc).
173+
174+
"
175+
`;
176+
177+
exports[`service:check integration non-federated should report traffic non-errors correctly vanilla 1`] = `
178+
"Loading Apollo Project [started]
179+
Loading Apollo Project [completed]
180+
Validating schema against tag master on graph engine [started]
181+
→ Resolving schema
182+
→ Validating schema
183+
Validated schema against tag master on graph engine [title changed]
184+
Validated schema against tag master on graph engine [completed]
185+
Comparing schema changes [started]
186+
Compared 1 schema change against 0 operations over the last 548 days [title changed]
187+
Compared 1 schema change against 0 operations over the last 548 days [completed]
188+
Reporting result [started]
189+
Found 0 breaking changes and 1 compatible change [title changed]
190+
Found 0 breaking changes and 1 compatible change [completed]
191+
192+
PASS ARG_CHANGED_TYPE \`Query.launches\` argument \`after\` has changed type from \`String\` to \`String!\`
193+
194+
View full details at: https://engine-staging.apollographql.com/service/justin-fullstack-tutorial/check/3acd7765-61b2-4f1a-9227-8b288e42bfdc
195+
"
196+
`;
197+
198+
exports[`service:check markdown formatting is correct with breaking changes 1`] = `
199+
"
200+
### Apollo Service Check
201+
🔄 Validated your local schema against schema tag \`staging\` on graph \`engine\`.
202+
🔢 Compared **18 schema changes** against **100 operations** seen over the **last 24 hours**.
203+
❌ Found **7 breaking changes** that would affect **3 operations** across **2 clients**
204+
205+
🔗 [View your service check details](https://engine-dev.apollographql.com/service/engine/checks?schemaTag=Detached%3A%20d664f715645c5f0bb5ad4f2260cd6cb8d19bbc68&schemaTagId=f9f68e7e-1b5f-4eab-a3da-1fd8cd681111&from=2019-03-26T22%3A25%3A12.887Z).
206+
"
207+
`;
208+
209+
exports[`service:check markdown formatting is correct with breaking changes 2`] = `
210+
"
211+
### Apollo Service Check
212+
🔄 Validated your local schema against schema tag \`staging\` on graph \`engine\`.
213+
🔢 Compared **1 schema change** against **1 operation** seen over the **last 24 hours**.
214+
❌ Found **1 breaking change** that would affect **1 operation** across **1 client**
215+
216+
🔗 [View your service check details](https://engine-dev.apollographql.com/service/engine/checks?schemaTag=Detached%3A%20d664f715645c5f0bb5ad4f2260cd6cb8d19bbc68&schemaTagId=f9f68e7e-1b5f-4eab-a3da-1fd8cd681111&from=2019-03-26T22%3A25%3A12.887Z).
217+
"
218+
`;
219+
220+
exports[`service:check markdown formatting is correct with no breaking changes 1`] = `
221+
"
222+
### Apollo Service Check
223+
🔄 Validated your local schema against schema tag \`staging\` on graph \`engine\`.
224+
🔢 Compared **0 schema changes** against **100 operations** seen over the **last 24 hours**.
225+
✅ Found **no breaking changes**.
226+
227+
🔗 [View your service check details](https://engine-dev.apollographql.com/service/engine/checks?schemaTag=Detached%3A%20d664f715645c5f0bb5ad4f2260cd6cb8d19bbc68&schemaTagId=f9f68e7e-1b5f-4eab-a3da-1fd8cd681111&from=2019-03-26T22%3A25%3A12.887Z).
228+
"
229+
`;

0 commit comments

Comments
 (0)