Skip to content

Commit 4c27acc

Browse files
author
Marc-Andre Giroux
committed
Iterate over implementations instead of allocating collections for isPossibleType
1 parent 1f92241 commit 4c27acc

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,17 @@ public boolean isPossibleType(Type abstractType, Type possibleType) {
623623
return false;
624624
} else {
625625
InterfaceTypeDefinition iFace = (InterfaceTypeDefinition) abstractTypeDef;
626-
List<ImplementingTypeDefinition> implementingTypeDefinitions = getAllImplementationsOf(iFace);
627-
return implementingTypeDefinitions.stream()
628-
.anyMatch(od -> od.getName().equals(targetObjectTypeDef.getName()));
626+
627+
return types.values().stream()
628+
.filter(ImplementingTypeDefinition.class::isInstance)
629+
.filter(t -> t.getName().equals(targetObjectTypeDef.getName()))
630+
.map(td -> (ImplementingTypeDefinition<?>) td)
631+
.anyMatch(itd -> itd.getImplements()
632+
.stream()
633+
.map(TypeInfo::getTypeName)
634+
.map(tn -> types.get(tn.getName()))
635+
.anyMatch(td -> td.getName().equals(iFace.getName()))
636+
);
629637
}
630638
}
631639

src/main/java/graphql/schema/idl/TypeInfo.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ public static TypeInfo typeInfo(Type type) {
2626
return new TypeInfo(type);
2727
}
2828

29+
public static TypeName getTypeName(Type type) {
30+
while (!(type instanceof TypeName)) {
31+
if (type instanceof NonNullType) {
32+
type = ((NonNullType) type).getType();
33+
}
34+
if (type instanceof ListType) {
35+
type = ((ListType) type).getType();
36+
}
37+
}
38+
return (TypeName) type;
39+
}
40+
2941
private final Type rawType;
3042
private final TypeName typeName;
3143
private final Deque<Class<?>> decoration = new ArrayDeque<>();

0 commit comments

Comments
 (0)