Skip to content

Commit ea4286a

Browse files
committed
wip
1 parent c91696c commit ea4286a

3 files changed

Lines changed: 94 additions & 105 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class ApolloEngineClient extends GraphQLDataSource {
7373
}
7474

7575
public async checkSchema(variables: CheckSchemaVariables) {
76+
// throw new Error(JSON.stringify({ ...variables, schema: "REDACTED" }));
7677
return this.execute<CheckSchema>({
7778
query: CHECK_SCHEMA,
7879
variables

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

Lines changed: 91 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -214,114 +214,100 @@ View full details at: https://engine-dev.apollographql.com/service/engine/checks
214214
// });
215215

216216
// // this is because of herkou-cli-utils hacky mocking system on their console logger
217-
// import { stdout, mockConsole } from "heroku-cli-util";
218-
// import path from "path";
219-
// import fs from "fs";
220-
// import { test as setup } from "apollo-cli-test";
221-
// import { introspectionQuery, print, execute, buildSchema } from "graphql";
222-
// import gql from "graphql-tag";
223-
// import { ENGINE_URI } from "../../../engine";
224-
// import { VALIDATE_SCHEMA } from "../../../operations/validateSchema";
217+
import { stdout, mockConsole } from "heroku-cli-util";
218+
import path from "path";
219+
import fs from "fs";
220+
import { test as setup } from "apollo-cli-test";
221+
import { introspectionQuery, print, execute, buildSchema } from "graphql";
222+
import gql from "graphql-tag";
223+
import { CHECK_SCHEMA } from "../../../../../apollo-language-server/src/engine/operations/checkSchema";
225224

226225
// import { vol, fs as mockFS } from "apollo-codegen-core/lib/localfs";
227226

228-
// const test = setup.do(() => mockConsole());
229-
// const ENGINE_API_KEY = "service:test:1234";
230-
// const hash = "12345";
231-
// const schemaContents = fs.readFileSync(
232-
// path.resolve(__dirname, "./fixtures/schema.graphql"),
233-
// {
234-
// encoding: "utf-8"
235-
// }
236-
// );
237-
238-
// const fullSchema = execute(buildSchema(schemaContents), gql(introspectionQuery))
239-
// .data;
240-
241-
// const localSuccess = nock => {
242-
// nock
243-
// .post("/graphql", {
244-
// query: print(gql(introspectionQuery)),
245-
// operationName: "IntrospectionQuery",
246-
// variables: {}
247-
// })
248-
// .reply(200, { data: fullSchema });
249-
// };
250-
251-
// const engineSuccess = ({ schema, tag, results } = {}) => nock => {
252-
// nock
253-
// .matchHeader("x-api-key", ENGINE_API_KEY)
254-
// .post("/", {
255-
// operationName: "CheckSchema",
256-
// variables: {
257-
// id: "test",
258-
// schema: schema || fullSchema.__schema,
259-
// tag: tag || "current",
260-
// gitContext: {
261-
// commit: /.+/i,
262-
// remoteUrl: /apollo-tooling/i,
263-
// committer: /@/i
264-
// }
265-
// },
266-
// query: print(VALIDATE_SCHEMA)
267-
// })
268-
// .reply(200, {
269-
// data: {
270-
// service: {
271-
// schema: {
272-
// checkSchema: {
273-
// changes: results || [
274-
// {
275-
// type: "NOTICE",
276-
// code: "DEPRECATION_ADDED",
277-
// description: "Field `User.lastName` was deprecated"
278-
// },
279-
// {
280-
// type: "WARNING",
281-
// code: "FIELD_REMOVED",
282-
// description: "Field `User.firstName` removed"
283-
// },
284-
// {
285-
// type: "FAILURE",
286-
// code: "ARG_CHANGE_TYPE",
287-
// description: "Argument id on `Query.user` changed to ID!"
288-
// },
289-
// {
290-
// type: "NOTICE",
291-
// code: "FIELD_ADDED",
292-
// description: "Field `User.fullName` was added"
293-
// }
294-
// ]
295-
// }
296-
// }
297-
// }
298-
// }
299-
// });
300-
// };
301-
302-
// jest.setTimeout(25000);
303-
304-
// beforeEach(() => {
305-
// vol.reset();
306-
// vol.fromJSON({
307-
// __blankFileSoDirectoryExists: ""
308-
// });
309-
// });
310-
311-
// describe("successful checks", () => {
312-
// test
313-
// .nock("http://localhost:4000", localSuccess)
314-
// .nock(ENGINE_URI, engineSuccess())
315-
// .env({ ENGINE_API_KEY })
316-
// .stdout()
317-
// .command(["schema:check"])
318-
// .exit(1)
319-
// .it("compares against the latest uploaded schema", () => {
320-
// expect(stdout).toContain("FAILURE");
321-
// expect(stdout).toContain("NOTICE");
322-
// expect(stdout).toContain("WARNING");
323-
// });
324-
227+
const test = setup.do(() => mockConsole());
228+
const ENGINE_URI = "https://engine-graphql.apollographql.com/api/graphql";
229+
const ENGINE_API_KEY = "service:test:1234";
230+
const hash = "12345";
231+
const schemaContents = fs.readFileSync(
232+
path.resolve(__dirname, "./fixtures/schema.graphql"),
233+
{
234+
encoding: "utf-8"
235+
}
236+
);
237+
238+
const fullSchema = execute(buildSchema(schemaContents), gql(introspectionQuery))
239+
.data;
240+
241+
const localSuccess = nock => {
242+
nock
243+
.post("/graphql", {
244+
query: print(gql(introspectionQuery)),
245+
operationName: "IntrospectionQuery",
246+
variables: {}
247+
})
248+
.reply(200, { data: fullSchema });
249+
};
250+
251+
const engineSuccess = ({
252+
schema,
253+
tag,
254+
results,
255+
resultFilter = () => true
256+
} = {}) => nock => {
257+
nock
258+
.matchHeader("x-api-key", ENGINE_API_KEY)
259+
.post(
260+
/.*/,
261+
// this is a matcher function
262+
({
263+
operationName,
264+
query,
265+
variables: { id, schema, gitContext, frontend }
266+
}) =>
267+
operationName === "CheckSchema" &&
268+
query === print(CHECK_SCHEMA) &&
269+
id === "test" &&
270+
gitContext &&
271+
JSON.stringify(schema) === JSON.stringify(fullSchema.__schema) &&
272+
frontend === "https://engine.apollographql.com"
273+
)
274+
.reply(200, {
275+
data: {
276+
service: {
277+
checkSchema: {
278+
...checkSchemaResult,
279+
diffToPrevious: {
280+
...checkSchemaResult.diffToPrevious,
281+
changes: (
282+
results || checkSchemaResult.diffToPrevious.changes
283+
).filter(resultFilter)
284+
}
285+
}
286+
}
287+
}
288+
});
289+
};
290+
291+
jest.setTimeout(25000);
292+
293+
describe("successful checks", () => {
294+
const noFailures = change => change.type !== "FAILURE";
295+
296+
test
297+
.fs({ "my.config.js": "module.exports = { }" })
298+
.nock("http://localhost:4000", localSuccess)
299+
.nock(ENGINE_URI, engineSuccess({ resultFilter: noFailures }))
300+
.env({ ENGINE_API_KEY })
301+
.stdout()
302+
.command(["service:check", "--config=my.config.js"])
303+
// .exit(1)
304+
.it("compares against the latest uploaded schema", () => {
305+
// throw new Error(stdout);
306+
expect(stdout).toContain("FAIL");
307+
// expect(stdout).toContain("NOTICE");
308+
// expect(stdout).toContain("WARNING");
309+
});
310+
});
325311
// test
326312
// .nock("http://localhost:4000", localSuccess)
327313
// .nock(ENGINE_URI, engineSuccess())

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ export default class ServiceCheck extends ProjectCommand {
348348
"compatible change"
349349
)}`;
350350

351+
throw new Error(task.title);
352+
351353
if (breakingSchemaChangeCount) {
352354
// Throw an error here to produce a red X in the list of steps being taken. We're going to
353355
// `catch` this error below and proceed with the reporting.

0 commit comments

Comments
 (0)