Skip to content

Commit 807388e

Browse files
ccouzensfabsrc
authored andcommitted
Test the input-value-deprecation flag
As requested #118 (review)
1 parent 54c39da commit 807388e

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $ graphql-schema-diff --help
3131
--left-schema-header Header to send to left remote schema source
3232
--right-schema-header Header to send to right remote schema source
3333
--sort-schema, -s Sort schemas prior to diffing
34-
--input-value-deprecation Include deprecated input value fields
34+
--input-value-deprecation Include deprecated input value fields when loading from URL
3535

3636
Examples
3737
$ graphql-schema-diff https://example.com/graphql schema.graphql

src/__tests__/diff.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import path from "path";
33
import { getDiff } from "../diff";
44
import { getIntrospectionQuery, parse, print } from "graphql";
55
import introspectionResponse from "./fixtures/introspectionResponse.json";
6+
import { graphql, buildSchema } from "graphql";
7+
import fs from "fs/promises";
68

79
describe("getDiff", () => {
810
describe("remote schema fetching", () => {
@@ -261,4 +263,63 @@ describe("getDiff", () => {
261263
expect(result).toBeUndefined();
262264
});
263265
});
266+
267+
describe("input arg deprecation", () => {
268+
it("introspection misses deprecated input args fields by default", async () => {
269+
const localSchemaInputValueDeprecated = path.join(
270+
__dirname,
271+
"fixtures/localSchemaInputValueDeprecated.graphql",
272+
);
273+
const testRemoteSchemaLocation = "http://test/graphql";
274+
const schema = buildSchema(
275+
await fs.readFile(localSchemaInputValueDeprecated, "utf-8"),
276+
);
277+
278+
nock(testRemoteSchemaLocation)
279+
.post(/.*/)
280+
.reply(200, (_uri, source: { query: string }) => {
281+
return graphql({ schema, source: source.query, rootValue: {} });
282+
});
283+
284+
const result = await getDiff(
285+
localSchemaInputValueDeprecated,
286+
testRemoteSchemaLocation,
287+
);
288+
289+
expect(result).toBeDefined();
290+
291+
if (result) {
292+
expect(result.diff).toContain("+ field1(testInput1: String): String");
293+
}
294+
});
295+
296+
it("introspection sees deprecated input args when inputValueDeprecation specified", async () => {
297+
const localSchemaInputValueDeprecated = path.join(
298+
__dirname,
299+
"fixtures/localSchemaInputValueDeprecated.graphql",
300+
);
301+
const testRemoteSchemaLocation = "http://test/graphql";
302+
const schema = buildSchema(
303+
await fs.readFile(localSchemaInputValueDeprecated, "utf-8"),
304+
);
305+
306+
nock(testRemoteSchemaLocation)
307+
.post(/.*/)
308+
.reply(200, (_uri, source: { query: string }) => {
309+
return graphql({ schema, source: source.query, rootValue: {} });
310+
});
311+
312+
const result = await getDiff(
313+
testRemoteSchemaLocation,
314+
localSchemaInputValueDeprecated,
315+
{ inputValueDeprecation: true },
316+
);
317+
318+
expect(result).toBeUndefined();
319+
});
320+
321+
afterEach(() => {
322+
nock.cleanAll();
323+
});
324+
});
264325
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type Query {
2+
field1(
3+
testInput1: String
4+
testInput2: Float @deprecated(reason: "test2 is deprecated")
5+
): String
6+
}

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const cli = meow(
2020
--left-schema-header \t Header to send to left remote schema source
2121
--right-schema-header \t Header to send to right remote schema source
2222
--sort-schema, -s \t\t Sort schemas prior to diffing
23-
--input-value-deprecation \t Include deprecated input value fields
23+
--input-value-deprecation \t Include deprecated input value fields when loading from URL
2424
2525
Examples
2626
$ graphql-schema-diff https://example.com/graphql schema.graphql

0 commit comments

Comments
 (0)