objectTypeFromClassMirror function
GraphQLObjectType?
objectTypeFromClassMirror(
- ClassMirror mirror
)
Implementation
@Deprecated('No replacement yet')
GraphQLObjectType? objectTypeFromClassMirror(ClassMirror mirror) {
if (_cache[mirror.reflectedType] != null) {
return _cache[mirror.reflectedType] as GraphQLObjectType?;
} else {}
var fields = <GraphQLObjectField>[];
var ready = <Symbol, MethodMirror>{};
var forward = <Symbol, MethodMirror>{};
void walkMap(Map<Symbol, MethodMirror> map) {
for (var name in map.keys) {
var methodMirror = map[name]!;
var exclude = _getExclude(name, methodMirror);
var canAdd = name != #hashCode &&
name != #runtimeType &&
!methodMirror.isPrivate &&
exclude?.canSerialize != true;
if (methodMirror.isGetter && canAdd) {
fields.add(fieldFromGetter(name, methodMirror, exclude, mirror));
}
}
}
bool isReady(TypeMirror returnType) {
var canContinue = returnType.reflectedType != mirror.reflectedType;
if (canContinue &&
returnType.isAssignableTo(reflectType(Iterable)) &&
returnType.typeArguments.isNotEmpty &&
!isReady(returnType.typeArguments[0])) {
canContinue = false;
}
return canContinue;
}
void prepReadyForward(Map<Symbol, MethodMirror> map) {
map.forEach((name, methodMirror) {
if (methodMirror.isGetter &&
name != #_identityHashCode &&
name != #runtimeType &&
name != #hashCode &&
MirrorSystem.getName(name) != '_identityHashCode') {
var returnType = methodMirror.returnType;
if (isReady(returnType)) {
ready[name] = methodMirror;
} else {
forward[name] = methodMirror;
}
}
});
}
prepReadyForward(mirror.instanceMembers);
walkMap(ready);
if (mirror.isAbstract) {
var decls = <Symbol, MethodMirror>{};
mirror.declarations.forEach((name, decl) {
if (decl is MethodMirror) {
decls[name] = decl;
}
});
ready.clear();
forward.clear();
prepReadyForward(decls);
walkMap(ready);
//walkMap(decls);
}
var inheritsFrom = <GraphQLObjectType>[];
var primitiveTypes = const <Type>[
String,
bool,
num,
int,
double,
Object,
dynamic,
Null,
Type,
Symbol
];
void walk(ClassMirror parent) {
if (!primitiveTypes.contains(parent.reflectedType)) {
if (parent.isAbstract) {
var obj = convertDartType(parent.reflectedType);
if (obj is GraphQLObjectType && !inheritsFrom.contains(obj)) {
inheritsFrom.add(obj);
}
}
walk(parent.superclass!);
parent.superinterfaces.forEach(walk);
}
}
walk(mirror.superclass!);
mirror.superinterfaces.forEach(walk);
var result = _cache[mirror.reflectedType];
if (result == null) {
result = objectType(
MirrorSystem.getName(mirror.simpleName),
fields: fields,
isInterface: mirror.isAbstract,
interfaces: inheritsFrom,
description: _getDescription(mirror.metadata),
);
_cache[mirror.reflectedType] = result;
walkMap(forward);
}
return result as GraphQLObjectType;
}