Skip to content

Commit e73ac24

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

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,16 @@ 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+
.anyMatch(tn -> tn.getName().equals(iFace.getName()))
635+
);
629636
}
630637
}
631638

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

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

29-
private final Type rawType;
30-
private final TypeName typeName;
31-
private final Deque<Class<?>> decoration = new ArrayDeque<>();
32-
33-
private TypeInfo(Type type) {
34-
this.rawType = assertNotNull(type, () -> "type must not be null");
29+
public static TypeName getTypeName(Type type) {
3530
while (!(type instanceof TypeName)) {
3631
if (type instanceof NonNullType) {
37-
decoration.push(NonNullType.class);
3832
type = ((NonNullType) type).getType();
3933
}
4034
if (type instanceof ListType) {
41-
decoration.push(ListType.class);
4235
type = ((ListType) type).getType();
4336
}
4437
}
45-
this.typeName = (TypeName) type;
38+
return (TypeName) type;
39+
}
40+
41+
private final Type rawType;
42+
private final TypeName typeName;
43+
private final Deque<Class<?>> decoration = new ArrayDeque<>();
44+
45+
private TypeInfo(Type type) {
46+
this.rawType = assertNotNull(type, () -> "type must not be null");
47+
this.typeName = getTypeName(type);
4648
}
4749

4850
public Type getRawType() {

0 commit comments

Comments
 (0)