Skip to content

Commit fcae1be

Browse files
authored
Merge pull request #212 from varahash/master
Fix resolving generic properties
2 parents 62ba0d3 + 16ffa00 commit fcae1be

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ internal class MethodFieldResolver(field: FieldDefinition, search: FieldResolver
103103

104104
override fun scanForMatches(): List<TypeClassMatcher.PotentialMatch> {
105105
val batched = isBatched(method, search)
106-
val unwrappedGenericType = genericType.unwrapGenericType(method.kotlinFunction?.returnType?.javaType ?: method.returnType)
106+
val unwrappedGenericType = genericType.unwrapGenericType(method.kotlinFunction?.returnType?.javaType ?: method.genericReturnType)
107107
val returnValueMatch = TypeClassMatcher.PotentialMatch.returnValue(field.type, unwrappedGenericType, genericType, SchemaClassScanner.ReturnValueReference(method), batched)
108108

109109
return field.inputValueDefinitions.mapIndexed { i, inputDefinition ->

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,24 @@ class EndToEndSpec extends Specification {
495495
]
496496
}
497497
498+
def "generated schema supports generic properties"() {
499+
when:
500+
def data = Utils.assertNoGraphQlErrors(gql) {
501+
'''
502+
{
503+
itemWithGenericProperties {
504+
keys
505+
}
506+
}
507+
'''
508+
}
509+
510+
then:
511+
data.itemWithGenericProperties == [
512+
keys: ["A", "B"]
513+
]
514+
}
515+
498516
def "generated schema supports batched datafetchers"() {
499517
when:
500518
def data = Utils.assertNoGraphQlErrors(batchedGql) {

src/test/kotlin/com/coxautodev/graphql/tools/EndToEndSpec.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Query {
5050
itemsWithOptionalInputExplicit(itemsInput: ItemSearchInput): [Item!]
5151
enumInputType(type: Type!): Type!
5252
customScalarMapInputType(customScalarMap: customScalarMap): customScalarMap
53+
itemWithGenericProperties: ItemWithGenericProperties!
5354
5455
defaultArgument(arg: Boolean = true): Boolean!
5556
defaultEnumListArgument(types: [Type] = [TYPE_1]): [Type]
@@ -199,6 +200,10 @@ type Tag {
199200
id: Int!
200201
name: String!
201202
}
203+
204+
type ItemWithGenericProperties {
205+
keys: [String!]!
206+
}
202207
"""
203208

204209

@@ -254,6 +259,7 @@ class Query: GraphQLQueryResolver, ListListResolver<String>() {
254259
fun itemsWithOptionalInputExplicit(input: Optional<ItemSearchInput>) = if(input.isPresent) items(input.get()) else items
255260
fun enumInputType(type: Type) = type
256261
fun customScalarMapInputType(customScalarMap: Map<String, Any>) = customScalarMap
262+
fun itemWithGenericProperties() = ItemWithGenericProperties(listOf("A", "B"))
257263

258264
fun defaultArgument(arg: Boolean) = arg
259265
fun defaultEnumListArgument(types: List<Type>) = types
@@ -355,6 +361,7 @@ data class NewItemInput(val name: String, val type: Type)
355361
data class ComplexNullable(val first: String, val second: String, val third: String)
356362
data class ComplexInputType(val first: String, val second: List<List<ComplexInputTypeTwo>?>?)
357363
data class ComplexInputTypeTwo(val first: String)
364+
data class ItemWithGenericProperties(val keys: List<String>)
358365

359366
val customScalarId = GraphQLScalarType("ID", "Overrides built-in ID", object : Coercing<UUID, String> {
360367
override fun serialize(input: Any): String? = when (input) {

0 commit comments

Comments
 (0)