Skip to content

Commit a39aec8

Browse files
andimarekbbakerman
andauthored
Schema transformer fix (#2078)
* Test showing the failure on schema transform * refactor schematransformer to use top sort instead of depth for traversing the graph * remove equals/hashcode for GraphQLList and GraphQLNonNull * cleanup * cleanup * cleanup * cleanup * add comment regarding equals * add additional test * implement final equals/hashcode with super calls to make sure it will not be broken in the future * handle empty breadcrumb list Co-authored-by: Brad Baker <bbaker@atlassian.com>
1 parent 49bbbeb commit a39aec8

22 files changed

Lines changed: 525 additions & 121 deletions

src/main/java/graphql/schema/GraphQLArgument.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,23 @@ public GraphQLArgument withNewChildren(SchemaElementChildrenContainer newChildre
184184
.replaceDirectives(newChildren.getChildren(CHILD_DIRECTIVES)));
185185
}
186186

187+
/**
188+
* {@inheritDoc}
189+
*/
190+
@Override
191+
public final boolean equals(Object o) {
192+
return super.equals(o);
193+
}
194+
195+
/**
196+
* {@inheritDoc}
197+
*/
198+
@Override
199+
public final int hashCode() {
200+
return super.hashCode();
201+
}
202+
203+
187204
/**
188205
* This helps you transform the current GraphQLArgument into another one by starting a builder with all
189206
* the current values and allows you to transform it how you want.

src/main/java/graphql/schema/GraphQLDirective.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,23 @@ public GraphQLDirective withNewChildren(SchemaElementChildrenContainer newChildr
140140
);
141141
}
142142

143+
/**
144+
* {@inheritDoc}
145+
*/
146+
@Override
147+
public final boolean equals(Object o) {
148+
return super.equals(o);
149+
}
150+
151+
/**
152+
* {@inheritDoc}
153+
*/
154+
@Override
155+
public final int hashCode() {
156+
return super.hashCode();
157+
}
158+
159+
143160
public static Builder newDirective() {
144161
return new Builder();
145162
}

src/main/java/graphql/schema/GraphQLEnumType.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class GraphQLEnumType implements GraphQLNamedInputType, GraphQLNamedOutpu
4545
public static final String CHILD_DIRECTIVES = "directives";
4646

4747

48-
4948
/**
5049
* @param name the name
5150
* @param description the description
@@ -236,6 +235,23 @@ public GraphQLEnumType withNewChildren(SchemaElementChildrenContainer newChildre
236235
);
237236
}
238237

238+
/**
239+
* {@inheritDoc}
240+
*/
241+
@Override
242+
public final boolean equals(Object o) {
243+
return super.equals(o);
244+
}
245+
246+
/**
247+
* {@inheritDoc}
248+
*/
249+
@Override
250+
public final int hashCode() {
251+
return super.hashCode();
252+
}
253+
254+
239255
public static Builder newEnum() {
240256
return new Builder();
241257
}

src/main/java/graphql/schema/GraphQLEnumValueDefinition.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,23 @@ public GraphQLEnumValueDefinition withNewChildren(SchemaElementChildrenContainer
171171
);
172172
}
173173

174+
/**
175+
* {@inheritDoc}
176+
*/
177+
@Override
178+
public final boolean equals(Object o) {
179+
return super.equals(o);
180+
}
181+
182+
/**
183+
* {@inheritDoc}
184+
*/
185+
@Override
186+
public final int hashCode() {
187+
return super.hashCode();
188+
}
189+
190+
174191
public static Builder newEnumValueDefinition() {
175192
return new Builder();
176193
}

src/main/java/graphql/schema/GraphQLFieldDefinition.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,23 @@ public GraphQLSchemaElement withNewChildren(SchemaElementChildrenContainer newCh
209209
);
210210
}
211211

212+
/**
213+
* {@inheritDoc}
214+
*/
215+
@Override
216+
public final boolean equals(Object o) {
217+
return super.equals(o);
218+
}
219+
220+
/**
221+
* {@inheritDoc}
222+
*/
223+
@Override
224+
public final int hashCode() {
225+
return super.hashCode();
226+
}
227+
228+
212229
public static Builder newFieldDefinition(GraphQLFieldDefinition existing) {
213230
return new Builder(existing);
214231
}

src/main/java/graphql/schema/GraphQLInputObjectField.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,23 @@ public GraphQLInputObjectField withNewChildren(SchemaElementChildrenContainer ne
165165
);
166166
}
167167

168+
/**
169+
* {@inheritDoc}
170+
*/
171+
@Override
172+
public final boolean equals(Object o) {
173+
return super.equals(o);
174+
}
175+
176+
/**
177+
* {@inheritDoc}
178+
*/
179+
@Override
180+
public final int hashCode() {
181+
return super.hashCode();
182+
}
183+
184+
168185
@Override
169186
public String toString() {
170187
return "GraphQLInputObjectField{" +

src/main/java/graphql/schema/GraphQLInputObjectType.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,23 @@ public GraphQLInputObjectType withNewChildren(SchemaElementChildrenContainer new
173173
);
174174
}
175175

176+
/**
177+
* {@inheritDoc}
178+
*/
179+
@Override
180+
public final boolean equals(Object o) {
181+
return super.equals(o);
182+
}
183+
184+
/**
185+
* {@inheritDoc}
186+
*/
187+
@Override
188+
public final int hashCode() {
189+
return super.hashCode();
190+
}
191+
192+
176193
@Override
177194
public String toString() {
178195
return "GraphQLInputObjectType{" +

src/main/java/graphql/schema/GraphQLInterfaceType.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,22 @@ void replaceInterfaces(List<GraphQLNamedOutputType> interfaces) {
228228
this.replacedInterfaces = sortTypes(interfaceComparator, interfaces);
229229
}
230230

231+
/**
232+
* {@inheritDoc}
233+
*/
234+
@Override
235+
public final boolean equals(Object o) {
236+
return super.equals(o);
237+
}
238+
239+
/**
240+
* {@inheritDoc}
241+
*/
242+
@Override
243+
public final int hashCode() {
244+
return super.hashCode();
245+
}
246+
231247

232248
public static Builder newInterface() {
233249
return new Builder();

src/main/java/graphql/schema/GraphQLList.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,30 @@ public GraphQLType getWrappedType() {
5151
return replacedWrappedType != null ? replacedWrappedType : originalWrappedType;
5252
}
5353

54+
public GraphQLType getOriginalWrappedType() {
55+
return originalWrappedType;
56+
}
57+
5458
void replaceType(GraphQLType type) {
5559
this.replacedWrappedType = type;
5660
}
5761

58-
@Override
59-
public boolean equals(Object o) {
62+
63+
public boolean isEqualTo(Object o) {
6064
if (this == o) {
6165
return true;
6266
}
6367
if (o == null || getClass() != o.getClass()) {
6468
return false;
6569
}
66-
6770
GraphQLList that = (GraphQLList) o;
6871
GraphQLType wrappedType = getWrappedType();
69-
72+
if (wrappedType instanceof GraphQLNonNull) {
73+
return ((GraphQLNonNull) wrappedType).isEqualTo(that.getWrappedType());
74+
}
7075
return Objects.equals(wrappedType, that.getWrappedType());
7176
}
7277

73-
@Override
74-
public int hashCode() {
75-
return getWrappedType() != null ? getWrappedType().hashCode() : 0;
76-
}
77-
7878
@Override
7979
public TraversalControl accept(TraverserContext<GraphQLSchemaElement> context, GraphQLTypeVisitor visitor) {
8080
return visitor.visitGraphQLList(this, context);
@@ -102,4 +102,20 @@ public String toString() {
102102
return GraphQLTypeUtil.simplePrint(this);
103103
}
104104

105+
/**
106+
* {@inheritDoc}
107+
*/
108+
@Override
109+
public final boolean equals(Object o) {
110+
return super.equals(o);
111+
}
112+
113+
/**
114+
* {@inheritDoc}
115+
*/
116+
@Override
117+
public final int hashCode() {
118+
return super.hashCode();
119+
}
120+
105121
}

src/main/java/graphql/schema/GraphQLNonNull.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* See http://graphql.org/learn/schema/#lists-and-non-null for more details on the concept
1919
*/
2020
@PublicApi
21-
2221
public class GraphQLNonNull implements GraphQLType, GraphQLInputType, GraphQLOutputType, GraphQLModifiedType {
2322

2423
/**
@@ -27,6 +26,7 @@ public class GraphQLNonNull implements GraphQLType, GraphQLInputType, GraphQLOut
2726
* {@code .type(nonNull(GraphQLString)) }
2827
*
2928
* @param wrappedType the type to wrap as being non null
29+
*
3030
* @return a GraphQLNonNull of that wrapped type
3131
*/
3232
public static GraphQLNonNull nonNull(GraphQLType wrappedType) {
@@ -55,31 +55,30 @@ public GraphQLType getWrappedType() {
5555
return replacedWrappedType != null ? replacedWrappedType : originalWrappedType;
5656
}
5757

58+
public GraphQLType getOriginalWrappedType() {
59+
return originalWrappedType;
60+
}
5861

5962
void replaceType(GraphQLType type) {
6063
assertNonNullWrapping(type);
6164
this.replacedWrappedType = type;
6265
}
6366

64-
@Override
65-
public boolean equals(Object o) {
67+
public boolean isEqualTo(Object o) {
6668
if (this == o) {
6769
return true;
6870
}
6971
if (o == null || getClass() != o.getClass()) {
7072
return false;
7173
}
72-
7374
GraphQLNonNull that = (GraphQLNonNull) o;
7475
GraphQLType wrappedType = getWrappedType();
75-
76+
if (wrappedType instanceof GraphQLList) {
77+
return ((GraphQLList) wrappedType).isEqualTo(that.getWrappedType());
78+
}
7679
return Objects.equals(wrappedType, that.getWrappedType());
7780
}
7881

79-
@Override
80-
public int hashCode() {
81-
return getWrappedType() != null ? getWrappedType().hashCode() : 0;
82-
}
8382

8483
@Override
8584
public String toString() {
@@ -107,4 +106,21 @@ public SchemaElementChildrenContainer getChildrenWithTypeReferences() {
107106
public GraphQLSchemaElement withNewChildren(SchemaElementChildrenContainer newChildren) {
108107
return nonNull(newChildren.getChildOrNull(CHILD_WRAPPED_TYPE));
109108
}
109+
110+
/**
111+
* {@inheritDoc}
112+
*/
113+
@Override
114+
public final boolean equals(Object o) {
115+
return super.equals(o);
116+
}
117+
118+
/**
119+
* {@inheritDoc}
120+
*/
121+
@Override
122+
public final int hashCode() {
123+
return super.hashCode();
124+
}
125+
110126
}

0 commit comments

Comments
 (0)