Skip to content

Commit

Permalink
SchemaMappingInspector consistently calls checkField
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rstoyanchev committed Mar 26, 2024
1 parent 651679b commit eb7bc43
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,18 +159,27 @@ private void checkFieldsContainer(
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));
}
}

Expand Down Expand Up @@ -247,10 +257,11 @@ private static boolean isNotScalarOrEnumType(GraphQLType type) {
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(
Expand Down

0 comments on commit eb7bc43

Please sign in to comment.