8000 Fix schemadiff input recursion (#1518) · mdekrey/graphql-java@fccc0c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit fccc0c7

Browse files
grrttedwardsbbakerman
authored andcommitted
Fix schemadiff input recursion (graphql-java#1518)
* Fix missing recursive call, add tests * Tidy up mkDotName to use String.join
1 parent 61d7c7b commit fccc0c7

17 files changed

+172
-1
lines changed

src/main/java/graphql/schema/diff/SchemaDiff.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ private void checkInputFields(DiffCtx ctx, TypeDefinition old, List<InputValueDe
390390
oldField.getName(), getAstDesc(oldField.getType()), getAstDesc(newField.get().getType()))
391391
.build());
392392
}
393+
394+
//
395+
// recurse via input types
396+
//
397+
checkType( ctx, oldField.getType(), newField.get().getType() );
393398
}
394399
}
395400

@@ -854,6 +859,6 @@ private static String capitalize(String name) {
854859
}
855860

856861
private String mkDotName(String... objectNames) {
857-
return Arrays.stream(objectNames).collect(Collectors.joining("."));
862+
return String.join(".", objectNames);
858863
}
859864
}

src/test/groovy/graphql/schema/diff/SchemaDiffTest.groovy

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,21 @@ class SchemaDiffTest extends Specification {
317317

318318
}
319319

320+
def "changed nested input object field types"() {
321+
DiffSet diffSet = diffSet("schema_changed_nested_input_object_fields.graphqls")
322+
323+
def diff = new SchemaDiff()
324+
diff.diffSchema(diffSet, chainedReporter)
325+
326+
expect:
327+
reporter.breakageCount == 1
328+
reporter.breakages[0].category == DiffCategory.INVALID
329+
reporter.breakages[0].typeName == 'NestedInput'
330+
reporter.breakages[0].typeKind == TypeKind.InputObject
331+
reporter.breakages[0].fieldName == 'nestedInput'
332+
333+
}
334+
320335
def "changed input object field types"() {
321336
DiffSet diffSet = diffSet("schema_changed_input_object_fields.graphqls")
322337

src/test/resources/diff/schema_ABaseLine.graphqls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ type Mutation {
2424
input Questor {
2525
beingID : ID
2626
queryTarget : String
27+
nestedInput : NestedInput
28+
}
29+
30+
input NestedInput {
31+
nestedInput: String
2732
}
2833

2934
scalar CustomScalar

src/test/resources/diff/schema_changed_field_arguments.graphqls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ type Mutation {
2525
input Questor {
2626
beingID : ID
2727
queryTarget : String
28+
nestedInput : NestedInput
29+
}
30+
31+
input NestedInput {
32+
nestedInput: String
2833
}
2934

3035
scalar CustomScalar

src/test/resources/diff/schema_changed_input_object_fields.graphqls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ type Mutation {
2424
input Questor {
2525
beingID : ID
2626
queryTarget : Int
27+
nestedInput : NestedInput
2728
newMandatoryField : String!
2829
}
2930

31+
input NestedInput {
32+
nestedInput: String
33+
}
34+
3035
scalar CustomScalar
3136

3237

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
schema {
2+
query : Query
3+
mutation : Mutation
4+
}
5+
6+
type Query {
7+
being(id : ID, type : String = "wizard") : Being
8+
beings(type : String) : [Being]
9+
10+
wizards : [Istari]
11+
gods : [Ainur]
12+
deities : [Deity]
13+
14+
allCharacters : [Character!] @deprecated(reason: "no longer supported")
15+
16+
customScalar : CustomScalar
17+
}
18+
19+
type Mutation {
20+
being(questor : Questor) : Query
21+
sword(bearer : Questor, name : String, alloy : String, temperament : Temperament) : String
22+
}
23+
24+
input Questor {
25+
beingID : ID
26+
queryTarget : String
27+
nestedInput : NestedInput
28+
}
29+
30+
input NestedInput {
31+
nestedInput: Int
32+
}
33+
34+
scalar CustomScalar
35+
36+
37+
interface Being {
38+
id : ID
39+
name : String
40+
nameInQuenyan : String
41+
invitedBy(id : ID) : Being
42+
}
43+
44+
45+
type Ainur implements Being {
46+
id : ID
47+
name : String
48+
nameInQuenyan : String
49+
invitedBy(id : ID) : Being
50+
loves : String
51+
}
52+
53+
54+
type Istari implements Being {
55+
id : ID
56+
name : String
57+
nameInQuenyan : String
58+
invitedBy(id : ID) : Being
59+
colour : String
60+
temperament : Temperament!
61+
62+
}
63+
64+
type Deity implements Being {
65+
id : ID
66+
name : String
67+
nameInQuenyan : String
68+
invitedBy(id : ID) : Being
69+
outlook : String
70+
}
71+
72+
union Character = Ainur | Istari | Deity
73+
74+
enum Temperament {
75+
Hero
76+
Duplicitous
77+
Evil
78+
}
79+
80+
81+

src/test/resources/diff/schema_changed_object_fields.graphqls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ type Mutation {
3030
input Questor {
3131
beingID : ID
3232
queryTarget : String
33+
nestedInput : NestedInput
34+
}
35+
36+
input NestedInput {
37+
nestedInput: String
3338
}
3439

3540
scalar CustomScalar

src/test/resources/diff/schema_changed_type_kind.graphqls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ type Mutation {
2424
input Questor {
2525
beingID : ID
2626
queryTarget : String
27+
nestedInput : NestedInput
28+
}
29+
30+
input NestedInput {
31+
nestedInput: String
2732
}
2833

2934
scalar CustomScalar

src/test/resources/diff/schema_dangerous_changes.graphqls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ type Mutation {
2424
input Questor {
2525
beingID : ID
2626
queryTarget : String
27+
nestedInput : NestedInput
28+
}
29+
30+
input NestedInput {
31+
nestedInput: String
2732
}
2833

2934
scalar CustomScalar

src/test/resources/diff/schema_interface_fields_missing.graphqls

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ type Mutation {
2424
input Questor {
2525
beingID : ID
2626
queryTarget : String
27+
nestedInput : NestedInput
28+
}
29+
30+
input NestedInput {
31+
nestedInput: String
2732
}
2833

2934
scalar CustomScalar

0 commit comments

Comments
 (0)
0