Skip to content

Commit 14baa4e

Browse files
committed
Polishing contribution
Closes: gh-1225
1 parent d3ff968 commit 14baa4e

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

spring-graphql/src/main/java/org/springframework/graphql/data/federation/FederationSchemaFactory.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -193,32 +193,31 @@ public SchemaTransformer createSchemaTransformer(TypeDefinitionRegistry registry
193193
private void checkEntityMappings(TypeDefinitionRegistry registry) {
194194
List<String> unmappedEntities = new ArrayList<>();
195195
for (TypeDefinition<?> type : registry.types().values()) {
196-
if (isEntityMappingExpected(type) && !this.handlerMethods.containsKey(type.getName())) {
197-
unmappedEntities.add(type.getName());
198-
}
196+
type.getDirectives().forEach((directive) -> {
197+
if (isResolvableKeyDirective(directive) && !this.handlerMethods.containsKey(type.getName())) {
198+
unmappedEntities.add(type.getName());
199+
}
200+
});
199201
}
200202
if (!unmappedEntities.isEmpty()) {
201203
throw new IllegalStateException("Unmapped entity types: " +
202204
unmappedEntities.stream().collect(Collectors.joining("', '", "'", "'")));
203205
}
204206
}
205207

206-
/**
207-
* Determine if a handler method is expected for this type: there is at least one '@key' directive
208-
* whose 'resolvable' argument resolves to true (either explicitly, or if the argument is not set).
209-
* @param type the type to inspect.
210-
* @return true if a handler method is expected for this type
211-
*/
212-
private boolean isEntityMappingExpected(TypeDefinition<?> type) {
213-
List<Directive> keyDirectives = type.getDirectives("key");
214-
return !keyDirectives.isEmpty() && keyDirectives.stream()
215-
.anyMatch((keyDirective) -> {
216-
Argument resolvableArg = keyDirective.getArgument("resolvable");
217-
return resolvableArg == null ||
218-
(resolvableArg.getValue() instanceof BooleanValue) && ((BooleanValue) resolvableArg.getValue()).isValue();
219-
});
208+
private boolean isResolvableKeyDirective(Directive directive) {
209+
if (!directive.getName().equalsIgnoreCase("key")) {
210+
return false;
211+
}
212+
Argument argument = directive.getArgument("resolvable");
213+
if (argument != null) {
214+
Object value = argument.getValue();
215+
return (value instanceof BooleanValue bv && bv.isValue());
216+
}
217+
return true;
220218
}
221219

220+
222221
public record EntityMappingInfo(String typeName, HandlerMethod handlerMethod) {
223222

224223
public boolean isBatchHandlerMethod() {

0 commit comments

Comments
 (0)