-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scan for resolvers that have a supertype of the data class #638
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,14 +249,18 @@ internal class SchemaClassScanner( | |
* Scan a new object for types that haven't been mapped yet. | ||
*/ | ||
private fun scanQueueItemForPotentialMatches(item: QueueItem) { | ||
val resolverInfoList = this.resolverInfos.filter { it.dataClassType == item.clazz } | ||
val resolverInfo: ResolverInfo = (if (resolverInfoList.size > 1) { | ||
MultiResolverInfo(resolverInfoList) | ||
val resolverInfoList = this.resolverInfos.filter { it.dataClassType.unwrap().isAssignableFrom(item.clazz.unwrap()) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets extract |
||
val resolverInfo: ResolverInfo = (if (resolverInfoList.size > 1 && item.clazz != Object::class.java) { | ||
MultiResolverInfo(resolverInfoList, item.clazz.unwrap()) | ||
} else { | ||
if (item.clazz == Object::class.java) { | ||
getResolverInfoFromTypeDictionary(item.type.name) | ||
} else { | ||
resolverInfosByDataClass[item.clazz] ?: DataClassResolverInfo(item.clazz) | ||
if (resolverInfoList.size == 1) { | ||
MultiResolverInfo(resolverInfoList, item.clazz.unwrap()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why multi if there's only one? |
||
} else { | ||
DataClassResolverInfo(item.clazz) | ||
} | ||
} | ||
}) | ||
?: throw throw SchemaClassScannerError("The GraphQL schema type '${item.type.name}' maps to a field of type java.lang.Object however there is no matching entry for this type in the type dictionary. You may need to add this type to the dictionary before building the schema.") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,8 @@ internal class FieldResolverScanner(val options: SchemaParserOptions) { | |
private fun verifyMethodArguments(method: Method, requiredCount: Int, search: Search): Boolean { | ||
val appropriateFirstParameter = if (search.requiredFirstParameterType != null) { | ||
method.genericParameterTypes.firstOrNull()?.let { | ||
it == search.requiredFirstParameterType || method.declaringClass.typeParameters.contains(it) | ||
it == search.requiredFirstParameterType || (it is Class<*> && it.unwrap().isAssignableFrom(search.requiredFirstParameterType)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the cast to Class here? |
||
|| method.declaringClass.typeParameters.contains(it) | ||
} ?: false | ||
} else { | ||
true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ import javax.servlet.http.Part | |
|
||
fun createSchema() = SchemaParser.newParser() | ||
.schemaString(schemaDefinition) | ||
.resolvers(Query(), Mutation(), Subscription(), ItemResolver(), UnusedRootResolver(), UnusedResolver(), EchoFilesResolver()) | ||
.resolvers(Query(), Mutation(), Subscription(), ItemResolver(), ItemInterfaceResolver(), UnusedRootResolver(), UnusedResolver(), EchoFilesResolver()) | ||
.scalars(customScalarUUID, customScalarMap, customScalarId, uploadScalar) | ||
.dictionary("OtherItem", OtherItemWithWrongName::class) | ||
.dictionary("ThirdItem", ThirdItem::class) | ||
|
@@ -155,6 +155,7 @@ type Item implements ItemInterface { | |
type: Type! | ||
uuid: UUID! | ||
tags(names: [String!]): [Tag!] | ||
uppercaseName: String! | ||
} | ||
|
||
type OtherItem implements ItemInterface { | ||
|
@@ -394,6 +395,10 @@ class ItemResolver : GraphQLResolver<Item> { | |
} | ||
} | ||
|
||
class ItemInterfaceResolver : GraphQLResolver<ItemInterface> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mind creating a separate test class with an example closer to the original issue instead of adding to this one? |
||
fun uppercaseName(item: ItemInterface): String = item.name.toUpperCase() | ||
} | ||
|
||
class EchoFilesResolver : GraphQLMutationResolver { | ||
fun echoFiles(fileParts: List<Part>): List<String> = fileParts.map { String(it.inputStream.readBytes()) } | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we fix this to find the correct type instead of deleting it?