Skip to content

Commit 2dacd8e

Browse files
committed
Refactor proxy handlers
1 parent ef3798b commit 2dacd8e

11 files changed

+67
-59
lines changed

src/main/kotlin/graphql/kickstart/tools/JavassistProxyHandler.kt

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main/kotlin/graphql/kickstart/tools/ProxyHandler.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/main/kotlin/graphql/kickstart/tools/SchemaParserBuilder.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package graphql.kickstart.tools
22

33
import com.fasterxml.jackson.databind.ObjectMapper
4+
import graphql.kickstart.tools.proxy.*
45
import graphql.kickstart.tools.relay.RelayConnectionFactory
56
import graphql.kickstart.tools.util.BiMap
67
import graphql.kickstart.tools.util.JavaType

src/main/kotlin/graphql/kickstart/tools/GuiceAopProxyHandler.java renamed to src/main/kotlin/graphql/kickstart/tools/proxy/GuiceAopProxyHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
package graphql.kickstart.tools;
1+
package graphql.kickstart.tools.proxy;
2+
3+
import graphql.kickstart.tools.GraphQLResolver;
24

35
public class GuiceAopProxyHandler implements ProxyHandler {
6+
47
@Override
58
public boolean canHandle(GraphQLResolver<?> resolver) {
69
return isGuiceProxy(resolver);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package graphql.kickstart.tools.proxy
2+
3+
import graphql.kickstart.tools.GraphQLResolver
4+
import javassist.util.proxy.ProxyFactory
5+
6+
/**
7+
* @author Marcus Thiesen
8+
*/
9+
class JavassistProxyHandler : ProxyHandler {
10+
11+
private val isEnabled: Boolean =
12+
try {
13+
Class.forName("javassist.util.proxy.ProxyFactory")
14+
true
15+
} catch (_: ClassNotFoundException) {
16+
false
17+
}
18+
19+
override fun canHandle(resolver: GraphQLResolver<*>): Boolean {
20+
return isEnabled && ProxyFactory.isProxyClass(resolver.javaClass)
21+
}
22+
23+
override fun getTargetClass(resolver: GraphQLResolver<*>): Class<*> = resolver.javaClass.superclass
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package graphql.kickstart.tools.proxy
2+
3+
import graphql.kickstart.tools.GraphQLResolver
4+
5+
/**
6+
* @author Marcus Thiesen
7+
*/
8+
interface ProxyHandler {
9+
10+
fun canHandle(resolver: GraphQLResolver<*>): Boolean
11+
12+
fun getTargetClass(resolver: GraphQLResolver<*>): Class<*>
13+
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package graphql.kickstart.tools
1+
package graphql.kickstart.tools.proxy
22

3+
import graphql.kickstart.tools.GraphQLResolver
34
import org.springframework.aop.support.AopUtils
45

56
/**
67
* @author Andrew Potter
78
*/
8-
9-
class Spring4AopProxyHandler: ProxyHandler {
9+
class Spring4AopProxyHandler : ProxyHandler {
1010

1111
val isEnabled: Boolean =
1212
try {
@@ -16,9 +16,9 @@ class Spring4AopProxyHandler: ProxyHandler {
1616
false
1717
}
1818

19-
override fun canHandle(resolver: GraphQLResolver<*>?): Boolean {
19+
override fun canHandle(resolver: GraphQLResolver<*>): Boolean {
2020
return isEnabled && AopUtils.isAopProxy(resolver)
2121
}
2222

23-
override fun getTargetClass(resolver: GraphQLResolver<*>?): Class<*> = AopUtils.getTargetClass(resolver)
24-
}
23+
override fun getTargetClass(resolver: GraphQLResolver<*>): Class<*> = AopUtils.getTargetClass(resolver)
24+
}

src/main/kotlin/graphql/kickstart/tools/WeldProxyHandler.java renamed to src/main/kotlin/graphql/kickstart/tools/proxy/WeldProxyHandler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package graphql.kickstart.tools;
1+
package graphql.kickstart.tools.proxy;
2+
3+
import graphql.kickstart.tools.GraphQLResolver;
4+
5+
public class WeldProxyHandler implements ProxyHandler {
26

3-
public class WeldProxyHandler implements ProxyHandler
4-
{
57
@Override
68
public boolean canHandle(GraphQLResolver<?> resolver) {
79
return isWeldProxy(resolver);

src/test/kotlin/graphql/kickstart/tools/DeepGenericsHierarchyTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import org.junit.Test
77
class PlaceTest {
88

99
@Test
10-
fun shouldHandleGenericsDeepHierarchy() {
10+
fun `should handle generics deep hierarchy`() {
1111
val schema = SchemaParser.newParser()
12-
.file("Place.graphqls")
13-
.resolvers(PlaceQuery())
14-
.build().makeExecutableSchema()
12+
.file("Place.graphqls")
13+
.resolvers(PlaceQuery())
14+
.build().makeExecutableSchema()
1515

1616
val graphql = GraphQL.newGraphQL(schema).build()
1717
val query = "query { places1 { id } places2 { id } }"

src/test/kotlin/graphql/kickstart/tools/EndToEndSpecHelper.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ fun createSchema() = SchemaParser.newParser()
2727
.makeExecutableSchema()
2828

2929
private const val schemaDefinition = """
30-
3130
## Private comment!
3231
scalar UUID
3332
scalar customScalarMap
@@ -211,38 +210,38 @@ type ItemWithGenericProperties {
211210
"""
212211

213212

214-
val items = mutableListOf(
213+
val items = listOf(
215214
Item(0, "item1", Type.TYPE_1, UUID.fromString("38f685f1-b460-4a54-a17f-7fd69e8cf3f8"), listOf(Tag(1, "item1-tag1"), Tag(2, "item1-tag2"))),
216215
Item(1, "item2", Type.TYPE_2, UUID.fromString("38f685f1-b460-4a54-b17f-7fd69e8cf3f8"), listOf(Tag(3, "item2-tag1"), Tag(4, "item2-tag2")))
217216
)
218217

219-
val otherItems = mutableListOf(
218+
val otherItems = listOf(
220219
OtherItemWithWrongName(0, "otherItem1", Type.TYPE_1, UUID.fromString("38f685f1-b460-4a54-c17f-7fd69e8cf3f8")),
221220
OtherItemWithWrongName(1, "otherItem2", Type.TYPE_2, UUID.fromString("38f685f1-b460-4a54-d17f-7fd69e8cf3f8"))
222221
)
223222

224-
val thirdItems = mutableListOf(
223+
val thirdItems = listOf(
225224
ThirdItem(100)
226225
)
227226

228-
val propetyHashMapItems = mutableListOf(
227+
val propetyHashMapItems = listOf(
229228
hashMapOf("name" to "bob", "age" to 55)
230229
)
231230

232-
val propertyMapMissingNamePropItems = mutableListOf(
231+
val propertyMapMissingNamePropItems = listOf(
233232
hashMapOf<String, Any>("age" to 55)
234233
)
235234

236-
val propetySortedMapItems = mutableListOf(
235+
val propetySortedMapItems = listOf(
237236
sortedMapOf("name" to "Arthur", "age" to 76),
238237
sortedMapOf("name" to "Jane", "age" to 28)
239238
)
240239

241-
val propertyMapWithComplexItems = mutableListOf(
240+
val propertyMapWithComplexItems = listOf(
242241
hashMapOf("nameId" to ComplexMapItem(150), "age" to 72)
243242
)
244243

245-
val propertyMapWithNestedComplexItems = mutableListOf(
244+
val propertyMapWithNestedComplexItems = listOf(
246245
hashMapOf("nested" to NestedComplexMapItem(UndiscoveredItem(63)), "age" to 72)
247246
)
248247

@@ -446,7 +445,7 @@ val customScalarMap = GraphQLScalarType.newScalar()
446445
})
447446
.build()
448447

449-
//Definition from https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/core/ApolloScalars.java
448+
// definition from https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/src/main/java/graphql/servlet/core/ApolloScalars.java
450449
val uploadScalar: GraphQLScalarType = GraphQLScalarType.newScalar()
451450
.name("Upload")
452451
.description("A file part in a multipart request")

0 commit comments

Comments
 (0)