Skip to content

Commit 6522ce2

Browse files
committed
Removed redundant ClassEntry class
1 parent db103a1 commit 6522ce2

File tree

6 files changed

+27
-62
lines changed

6 files changed

+27
-62
lines changed

src/main/kotlin/com/coxautodev/graphql/tools/ClassEntry.kt

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

src/main/kotlin/com/coxautodev/graphql/tools/GenericType.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ internal open class GenericType(protected val mostSpecificType: JavaType, protec
114114
declaringType
115115
} else {
116116
val superclass = declaringType.unwrap().genericSuperclass
117-
parameterizedDeclaringTypeOrSuperType(superclass)
117+
if (superclass != null) {
118+
parameterizedDeclaringTypeOrSuperType(superclass)
119+
} else {
120+
null
121+
}
118122
}
119123

120124
private fun unwrapGenericType(declaringType: ParameterizedType, type: TypeVariable<*>) =

src/main/kotlin/com/coxautodev/graphql/tools/SchemaClassScanner.kt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ internal class SchemaClassScanner(initialDictionary: BiMap<String, Class<*>>, al
133133
// Union types can also be excluded, as their possible types are resolved recursively later
134134
val dictionary = try {
135135
Maps.unmodifiableBiMap(HashBiMap.create<TypeDefinition<*>, JavaType>().also {
136-
dictionary.filter { it.value.type() != null && it.key !is InputObjectTypeDefinition && it.key !is UnionTypeDefinition }.mapValuesTo(it) { it.value.type() }
136+
dictionary.filter { it.value.javaType != null && it.key !is InputObjectTypeDefinition && it.key !is UnionTypeDefinition }.mapValuesTo(it) { it.value.javaType }
137137
})
138138
} catch (t: Throwable) {
139139
throw SchemaClassScannerError("Error creating bimap of type => class", t)
@@ -205,7 +205,7 @@ internal class SchemaClassScanner(initialDictionary: BiMap<String, Class<*>>, al
205205
val dictionaryContainsType = dictionary.filter { it.key.name == type.name }.isNotEmpty()
206206
if (!unvalidatedTypes.contains(type) && !dictionaryContainsType) {
207207
val initialEntry = initialDictionary[type.name] ?: throw SchemaClassScannerError(failureMessage(type))
208-
handleFoundType(type, ClassEntry.of(initialEntry.get()), DictionaryReference())
208+
handleFoundType(type, initialEntry.get(), DictionaryReference())
209209
}
210210
}
211211
}
@@ -244,7 +244,7 @@ internal class SchemaClassScanner(initialDictionary: BiMap<String, Class<*>>, al
244244
}
245245

246246
is TypeClassMatcher.ValidMatch -> {
247-
handleFoundType(match.type, match.classEntry, match.reference)
247+
handleFoundType(match.type, match.javaType, match.reference)
248248
}
249249
}
250250
}
@@ -256,27 +256,27 @@ internal class SchemaClassScanner(initialDictionary: BiMap<String, Class<*>>, al
256256
/**
257257
* Enter a found type into the dictionary if it doesn't exist yet, add a reference pointing back to where it was discovered.
258258
*/
259-
private fun handleFoundType(type: TypeDefinition<*>, classEntry: ClassEntry?, reference: Reference) {
259+
private fun handleFoundType(type: TypeDefinition<*>, javaType: JavaType?, reference: Reference) {
260260
val realEntry = dictionary.getOrPut(type) { DictionaryEntry() }
261261
var typeWasSet = false
262262

263-
if (classEntry != null) {
264-
typeWasSet = realEntry.setTypeIfMissing(classEntry)
263+
if (javaType != null) {
264+
typeWasSet = realEntry.setTypeIfMissing(javaType)
265265

266-
if (realEntry.classEntry != classEntry) {
266+
if (realEntry.javaType != javaType) {
267267
if (options.preferGraphQLResolver && realEntry.hasResolverRef()) {
268-
log.warn("The real entry ${realEntry.joinReferences()} is a GraphQLResolver so ignoring this one ${classEntry.clazz} $reference")
268+
log.warn("The real entry ${realEntry.joinReferences()} is a GraphQLResolver so ignoring this one ${javaType.unwrap()} $reference")
269269
} else {
270-
throw SchemaClassScannerError("Two different classes used for type ${type.name}:\n${realEntry.joinReferences()}\n\n- ${classEntry.clazz}:\n| ${reference.getDescription()}")
270+
throw SchemaClassScannerError("Two different classes used for type ${type.name}:\n${realEntry.joinReferences()}\n\n- ${javaType.unwrap()}:\n| ${reference.getDescription()}")
271271
}
272272
}
273273
}
274274

275275
realEntry.addReference(reference)
276276

277277
// Check if we just added the entry... a little odd, but it works (and thread-safe, FWIW)
278-
if (typeWasSet && classEntry != null) {
279-
handleNewType(type, classEntry.type)
278+
if (typeWasSet && javaType != null) {
279+
handleNewType(type, javaType)
280280
}
281281
}
282282

@@ -356,21 +356,21 @@ internal class SchemaClassScanner(initialDictionary: BiMap<String, Class<*>>, al
356356

357357
private class DictionaryEntry {
358358
private val references = mutableListOf<Reference>()
359-
var classEntry: ClassEntry? = null
359+
var javaType: JavaType? = null
360360
private set
361361

362-
fun setTypeIfMissing(classEntry: ClassEntry): Boolean {
363-
if (this.classEntry == null) {
364-
this.classEntry = classEntry
362+
fun setTypeIfMissing(javaType: JavaType): Boolean {
363+
if (this.javaType == null) {
364+
this.javaType = javaType
365365
return true
366366
}
367367

368368
return false
369369
}
370370

371-
fun type(): JavaType? = classEntry?.type
371+
// fun type(): JavaType? = classEntry?.type
372372

373-
fun typeClass(): Class<out Any>? = classEntry?.clazz
373+
fun typeClass(): Class<out Any>? = javaType?.unwrap()
374374

375375
fun addReference(reference: Reference) {
376376
references.add(reference)

src/main/kotlin/com/coxautodev/graphql/tools/TypeClassMatcher.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ internal class TypeClassMatcher(private val definitionsByName: Map<String, TypeD
9090
if (typeDefinition is ScalarTypeDefinition) {
9191
ScalarMatch(typeDefinition)
9292
} else {
93-
ValidMatch(typeDefinition, ClassEntry.of(realType), potentialMatch.reference)
93+
ValidMatch(typeDefinition, realType, potentialMatch.reference)
9494
}
9595
}
9696

97-
is TypeDefinition<*> -> ValidMatch(graphQLType, ClassEntry.of(realType), potentialMatch.reference)
97+
is TypeDefinition<*> -> ValidMatch(graphQLType, realType, potentialMatch.reference)
9898
else -> throw error(potentialMatch, "Unknown type: ${realType.javaClass.name}")
9999
}
100100
}
@@ -116,7 +116,7 @@ internal class TypeClassMatcher(private val definitionsByName: Map<String, TypeD
116116

117117
internal interface Match
118118
internal data class ScalarMatch(val type: ScalarTypeDefinition) : Match
119-
internal data class ValidMatch(val type: TypeDefinition<*>, val classEntry: ClassEntry, val reference: SchemaClassScanner.Reference) : Match
119+
internal data class ValidMatch(val type: TypeDefinition<*>, val javaType: JavaType, val reference: SchemaClassScanner.Reference) : Match
120120
internal enum class Location(val prettyName: String) {
121121
RETURN_TYPE("return type"),
122122
PARAMETER_TYPE("parameter"),
@@ -132,5 +132,4 @@ internal class TypeClassMatcher(private val definitionsByName: Map<String, TypeD
132132
}
133133
}
134134

135-
class RawClassRequiredForGraphQLMappingException(msg: String) : RuntimeException(msg)
136135
}

src/test/groovy/com/coxautodev/graphql/tools/RelayConnectionSpec.groovy

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ package com.coxautodev.graphql.tools
33
import graphql.GraphQL
44
import graphql.execution.AsyncExecutionStrategy
55
import graphql.relay.Connection
6-
import graphql.relay.DefaultConnection
7-
import graphql.relay.Edge
86
import graphql.relay.SimpleListConnection
97
import graphql.schema.DataFetchingEnvironment
108
import graphql.schema.GraphQLSchema
11-
import spock.lang.Shared
129
import spock.lang.Specification
1310

1411
class RelayConnectionSpec extends Specification {

src/test/groovy/com/coxautodev/graphql/tools/TypeClassMatcherSpec.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class TypeClassMatcherSpec extends Specification {
6363
then:
6464
noExceptionThrown()
6565
match.type == customDefinition
66-
match.classEntry.clazz == CustomType
66+
match.javaType == CustomType
6767

6868
where:
6969
methodName | type
@@ -119,7 +119,7 @@ class TypeClassMatcherSpec extends Specification {
119119
then:
120120
noExceptionThrown()
121121
match.type == unwrappedCustomDefinition
122-
match.classEntry.clazz == UnwrappedGenericCustomType
122+
match.javaType.getRawType() == UnwrappedGenericCustomType
123123
}
124124

125125
private class Super<Unused, Type, ListFutureType> implements GraphQLQueryResolver {

0 commit comments

Comments
 (0)