Skip to content

Commit d67e907

Browse files
sebasjmyrashk
authored andcommitted
Problem: extending generic class duplicate field definition (#36)
Solution: exclude bridge methods
1 parent 1b6531e commit d67e907

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.iml
44
*.ipr
55
*.iws
6+
/.nb-gradle/

src/main/java/graphql/annotations/GraphQLAnnotations.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ public boolean equals(Object obj) {
200200

201201
Class<?> declaringClass = getDeclaringClass(method);
202202

203-
boolean valid = (method.getAnnotation(GraphQLField.class) != null ||
204-
declaringClass.getMethod(method.getName(), method.getParameterTypes()).getAnnotation(GraphQLField.class) != null);
203+
boolean valid = (method.getAnnotation(GraphQLField.class) != null ||
204+
declaringClass.getMethod(method.getName(), method.getParameterTypes()).getAnnotation(GraphQLField.class) != null)
205+
&& !method.isBridge();
205206

206207
if (valid) {
207208
builder.field(getField(method));

src/test/java/graphql/annotations/GraphQLObjectTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,38 @@ public void methodInheritance() {
188188
assertEquals(((Map<String, Object>)result.getData()).get("field1"), "inherited");
189189
}
190190

191+
private static class TestObjectBridgMethodParent<Type> {
192+
private final Type id;
193+
public TestObjectBridgMethodParent(Type id) {
194+
this.id = id;
195+
}
196+
public Type id() {
197+
return id;
198+
}
199+
}
200+
201+
private static class TestObjectBridgMethod extends TestObjectBridgMethodParent<Long> {
202+
203+
public TestObjectBridgMethod() {
204+
super(1l);
205+
}
206+
207+
@Override @GraphQLField
208+
public Long id() {
209+
return super.id();
210+
}
211+
}
212+
213+
@Test @SneakyThrows
214+
public void methodInheritanceWithGenerics() {
215+
GraphQLObjectType object = GraphQLAnnotations.object(TestObjectBridgMethod.class);
216+
217+
GraphQLSchema schema = newSchema().query(object).build();
218+
219+
ExecutionResult result = new GraphQL(schema).execute("{id}", new TestObjectBridgMethod());
220+
assertEquals(((Map<String, Object>)result.getData()).get("id"), 1l);
221+
}
222+
191223
public interface Iface {
192224
@GraphQLField
193225
default String field() {

0 commit comments

Comments
 (0)