Filter out Kotlin Continuation when resolving arguments

The `kotlin.coroutines.Continuation` argument that is passed for
suspended function was parsed erroneously as a GraphQL "source"
argument. This commit adds a resolver for Continuation that resolves
it  to `null`, which allows suspended functions to work.

Closes gh-132
This commit is contained in:
Koen Punt
2021-09-16 12:02:26 +02:00
committed by Rossen Stoyanchev
parent 892d2bd344
commit 3ef86492e3
2 changed files with 29 additions and 0 deletions

View File

@@ -34,6 +34,7 @@ import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.KotlinDetector;
import org.springframework.core.MethodIntrospector;
import org.springframework.core.MethodParameter;
import org.springframework.core.ParameterizedTypeReference;
@@ -163,6 +164,10 @@ public class AnnotatedDataFetcherConfigurer
this.argumentResolvers.addResolver(new DataFetchingEnvironmentMethodArgumentResolver());
this.argumentResolvers.addResolver(new DataLoaderMethodArgumentResolver());
if (KotlinDetector.isKotlinPresent()) {
this.argumentResolvers.addResolver(new ContinuationHandlerMethodArgumentResolver());
}
// This works as a fallback, after all other resolvers
this.argumentResolvers.addResolver(new SourceMethodArgumentResolver());
}

View File

@@ -0,0 +1,24 @@
package org.springframework.graphql.data.method.annotation.support;
import graphql.schema.DataFetchingEnvironment;
import org.springframework.core.MethodParameter;
import org.springframework.graphql.data.method.HandlerMethodArgumentResolver;
/**
* No-op resolver for method arguments of type {@link kotlin.coroutines.Continuation}.
*
* @author Koen Punt
* @since 5.3
*/
public class ContinuationHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver {
@Override
public boolean supportsParameter(MethodParameter parameter) {
return "kotlin.coroutines.Continuation".equals(parameter.getParameterType().getName());
}
@Override
public Object resolveArgument(MethodParameter parameter, DataFetchingEnvironment environment) throws Exception {
return null;
}
}