public static AnnotatedType of(AnnotatedType[] types) {
Objects.requireNonNull(types);
if (types.length < 2) {
if (types.length == 1 && GenericTypeReflector.isSuperType(Union.class, types[0].getType())) {
return types[0];
}
throw new IllegalArgumentException(SINGLE_TYPE_UNION_ERROR);
}
AnnotatedType[] distinctTypes = dedupe(types);
Class union;
try {
union = ClassUtils.forName(Union.class.getName() + distinctTypes.length);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Unions of more than 10 types are not supported");
}
Annotation unionAnnotation = stream(ClassUtils.getAllAnnotations(stream(types)))
.filter(annotation -> annotation.annotationType().equals(GraphQLUnion.class))
.filter(annotation -> !((GraphQLUnion) annotation).description().isEmpty())
.findFirst().orElse(types[0].getAnnotation(GraphQLUnion.class));
return TypeFactory.parameterizedAnnotatedClass(union, new Annotation[] {unionAnnotation}, distinctTypes);
}
Union.java 文件源码
java
阅读 39
收藏 0
点赞 0
评论 0
项目:graphql-spqr
作者:
评论列表
文章目录