SchemaMappingInspector consistently calls checkField

Rather than only checking for the presence of a property, also call
checkField on it. If it is a scalar then recursion stop anyway, but in the
unlikely event that it isn't, there are more fields to check.

Closes gh-934
This commit is contained in:
rstoyanchev
2024-03-26 07:45:11 +00:00
parent 651679b8ff
commit eb7bc43ce9

View File

@@ -16,6 +16,7 @@
package org.springframework.graphql.execution;
import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -158,18 +159,27 @@ public class SchemaMappingInspector {
for (GraphQLFieldDefinition field : fieldContainer.getFieldDefinitions()) {
String fieldName = field.getName();
DataFetcher<?> dataFetcher = dataFetcherMap.get(fieldName);
if (dataFetcher != null) {
if (dataFetcher instanceof SelfDescribingDataFetcher<?> sd) {
checkFieldArguments(field, sd);
checkField(fieldContainer, field, sd.getReturnType());
if (dataFetcher instanceof SelfDescribingDataFetcher<?> selfDescribing) {
checkFieldArguments(field, selfDescribing);
checkField(fieldContainer, field, selfDescribing.getReturnType());
}
else {
checkField(fieldContainer, field, ResolvableType.NONE);
}
continue;
}
else if (resolvableType == null || !hasProperty(resolvableType, fieldName)) {
this.reportBuilder.unmappedField(FieldCoordinates.coordinates(typeName, fieldName));
if (resolvableType != null) {
PropertyDescriptor descriptor = getProperty(resolvableType, fieldName);
if (descriptor != null) {
checkField(fieldContainer, field, ResolvableType.forMethodReturnType(descriptor.getReadMethod()));
continue;
}
}
this.reportBuilder.unmappedField(FieldCoordinates.coordinates(typeName, fieldName));
}
}
@@ -247,10 +257,11 @@ public class SchemaMappingInspector {
return !(type instanceof GraphQLScalarType || type instanceof GraphQLEnumType);
}
private boolean hasProperty(ResolvableType resolvableType, String fieldName) {
@Nullable
private PropertyDescriptor getProperty(ResolvableType resolvableType, String fieldName) {
try {
Class<?> clazz = resolvableType.resolve(Object.class);
return (BeanUtils.getPropertyDescriptor(clazz, fieldName) != null);
return BeanUtils.getPropertyDescriptor(clazz, fieldName);
}
catch (BeansException ex) {
throw new IllegalStateException(