Skip to content

Commit 521c6d7

Browse files
committed
Problem: accessing original class behind GraphQLObjectType is impossible
Solution: pass the original class to GraphQLObjectTypeWrapper and add a getter
1 parent d3e5491 commit 521c6d7

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version = 0.13.0
1+
version = 0.13.1
22
group = com.graphql-java

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,13 @@ private Class<?> getDeclaringClass(Method method) {
167167
NoSuchMethodException {
168168
GraphQLObjectType.Builder builder = getObjectBuilder(object);
169169

170-
return new GraphQLObjectTypeWrapper(builder.build());
170+
return new GraphQLObjectTypeWrapper(object, builder.build());
171171
}
172172

173173
public static GraphQLObjectType object(Class<?> object) throws IllegalAccessException, InstantiationException, NoSuchMethodException {
174174
return getInstance().getObject(object);
175175
}
176176

177-
public static class GraphQLObjectTypeWrapper extends GraphQLObjectType {
178-
179-
public GraphQLObjectTypeWrapper(GraphQLObjectType objectType) {
180-
super(objectType.getName(), objectType.getDescription(), objectType.getFieldDefinitions(),
181-
objectType.getInterfaces());
182-
}
183-
184-
@Override
185-
public boolean equals(Object obj) {
186-
return obj instanceof GraphQLObjectType &&
187-
((GraphQLObjectType) obj).getName().contentEquals(getName()) &&
188-
((GraphQLObjectType) obj).getFieldDefinitions().equals(getFieldDefinitions());
189-
}
190-
}
191-
192177
public static class GraphQLFieldDefinitionWrapper extends GraphQLFieldDefinition {
193178

194179
public GraphQLFieldDefinitionWrapper(GraphQLFieldDefinition fieldDefinition) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package graphql.annotations;
2+
3+
import graphql.schema.GraphQLObjectType;
4+
import lombok.Getter;
5+
6+
public class GraphQLObjectTypeWrapper extends GraphQLObjectType {
7+
8+
@Getter
9+
private final Class<?> objectClass;
10+
11+
public GraphQLObjectTypeWrapper(Class<?> objectClass, GraphQLObjectType objectType) {
12+
super(objectType.getName(), objectType.getDescription(), objectType.getFieldDefinitions(),
13+
objectType.getInterfaces());
14+
this.objectClass = objectClass;
15+
}
16+
17+
@Override
18+
public boolean equals(Object obj) {
19+
return obj instanceof GraphQLObjectType &&
20+
((GraphQLObjectType) obj).getName().contentEquals(getName()) &&
21+
((GraphQLObjectType) obj).getFieldDefinitions().equals(getFieldDefinitions());
22+
}
23+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ public void metainformation() {
117117
assertEquals(object.getDescription(), "TestObject object");
118118
}
119119

120+
@Test @SneakyThrows
121+
public void objectClass() {
122+
GraphQLObjectType object = GraphQLAnnotations.object(TestObject.class);
123+
assertTrue(object instanceof GraphQLObjectTypeWrapper);
124+
assertEquals(((GraphQLObjectTypeWrapper) object).getObjectClass(), TestObject.class);
125+
}
126+
120127
@Test @SneakyThrows
121128
public void fields() {
122129
GraphQLObjectType object = GraphQLAnnotations.object(TestObject.class);

0 commit comments

Comments
 (0)