graphql-java-kickstart/graphql-java-tools

Unable to union MutationResolver and SubscriptionResolver in one class

bostandyksoft opened this issue · 3 comments

Since update to 3.1.0 version (previous was 13.0.2)

Description

There is class, that union Mutation and Subscription resolver interfaces

@Component
public class UserAttributeMutation implements GraphQLMutationResolver, GraphQLSubscriptionResolver {

Expected behavior

FieldResolverScanner can find all methods

Actual behavior

FieldResolverScanner resolves only subscription method

Steps to reproduce the bug

It happens because there in following method

private fun getAllMethods(search: Search): List<Method> {
       val type = search.type.unwrap()
       val declaredMethods = type.declaredNonProxyMethods
       val superClassesMethods = ClassUtils.getAllSuperclasses(type).flatMap { it.methods.toList() }
       val interfacesMethods = ClassUtils.getAllInterfaces(type).flatMap { it.methods.toList() }

       return (declaredMethods + superClassesMethods + interfacesMethods)
           .asSequence()
           .filter { !it.isSynthetic }
           .filter { !Modifier.isPrivate(it.modifiers) }
           // discard any methods that are coming off the root of the class hierarchy
           // to avoid issues with duplicate method declarations
           .filter { it.declaringClass != Object::class.java }
           // subscription resolvers must return a publisher
           .filter { search.source !is GraphQLSubscriptionResolver || resolverMethodReturnsPublisher(it) }
           .toList()
   }

was added new filter
.filter { search.source !is GraphQLSubscriptionResolver || resolverMethodReturnsPublisher(it) }

So, all methods, that not return Publisher are ignored

Related to: #756