Skip to content

Commit a3977ba

Browse files
committed
Parent/source resolver allows CharSequence and Number
Closes gh-370
1 parent 54b1396 commit a3977ba

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/SourceMethodArgumentResolver.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,29 @@
1515
*/
1616
package org.springframework.graphql.data.method.annotation.support;
1717

18+
import java.net.URI;
19+
import java.net.URL;
20+
import java.time.temporal.Temporal;
1821
import java.util.Collection;
22+
import java.util.Date;
23+
import java.util.Locale;
1924

2025
import graphql.schema.DataFetchingEnvironment;
2126

22-
import org.springframework.beans.BeanUtils;
2327
import org.springframework.core.MethodParameter;
2428
import org.springframework.graphql.data.method.HandlerMethodArgumentResolver;
2529
import org.springframework.util.Assert;
30+
import org.springframework.util.ClassUtils;
2631

2732
/**
2833
* Resolver for the source/parent of a field, obtained via
2934
* {@link DataFetchingEnvironment#getSource()}.
3035
*
31-
* <p>This resolver supports any non-simple value type, also excluding arrays
32-
* and collections, and therefore must be ordered last, in a fallback mode,
33-
* allowing other resolvers to resolve the argument first.
36+
* <p>This resolver supports any type excluding enums, dates, arrays,
37+
*
38+
* wide range of types, including any non-simple
39+
* type, along with any CharSequence, or Number. Hence, it must come last in
40+
* the order or resolvers, as a fallback after all others.
3441
*
3542
* @author Rossen Stoyanchev
3643
* @since 1.0.0
@@ -40,7 +47,20 @@ public class SourceMethodArgumentResolver implements HandlerMethodArgumentResolv
4047
@Override
4148
public boolean supportsParameter(MethodParameter parameter) {
4249
Class<?> type = parameter.getParameterType();
43-
return (!BeanUtils.isSimpleValueType(type) && !type.isArray() && !Collection.class.isAssignableFrom(type));
50+
return (!isExcludedSimpleValueType(type) && !type.isArray() && !Collection.class.isAssignableFrom(type));
51+
}
52+
53+
private static boolean isExcludedSimpleValueType(Class<?> type) {
54+
// Same as BeanUtils.isSimpleValueType except for CharSequence and Number
55+
return (Void.class != type && void.class != type &&
56+
(ClassUtils.isPrimitiveOrWrapper(type) ||
57+
Enum.class.isAssignableFrom(type) ||
58+
Date.class.isAssignableFrom(type) ||
59+
Temporal.class.isAssignableFrom(type) ||
60+
URI.class == type ||
61+
URL.class == type ||
62+
Locale.class == type ||
63+
Class.class == type));
4464
}
4565

4666
@Override

0 commit comments

Comments
 (0)