Introspection of interface types complete
This commit is contained in:
parent
5753319b92
commit
10dda84f95
3 changed files with 67 additions and 19 deletions
|
@ -61,10 +61,15 @@ main() async {
|
|||
print('Access graphiql at $graphiqlUri');
|
||||
}
|
||||
|
||||
@GraphQLDocumentation(description: 'Any object with a .text (String) property.')
|
||||
abstract class HasText {
|
||||
String get text;
|
||||
}
|
||||
|
||||
@serializable
|
||||
@GraphQLDocumentation(
|
||||
description: 'A task that might not be completed yet. **Yay! Markdown!**')
|
||||
class Todo extends Model {
|
||||
class Todo extends Model implements HasText {
|
||||
String text;
|
||||
|
||||
@GraphQLDocumentation(deprecationReason: 'Use `completion_status` instead.')
|
||||
|
|
|
@ -427,12 +427,8 @@ List<GraphQLType> _fetchAllTypesFromObject(GraphQLObjectType objectType) {
|
|||
}
|
||||
}
|
||||
|
||||
for (var type in objectType.interfaces) {
|
||||
types.addAll(_fetchAllTypesFromObject(type));
|
||||
}
|
||||
|
||||
for (var type in objectType.possibleTypes) {
|
||||
types.addAll(_fetchAllTypesFromObject(type));
|
||||
for (var i in objectType.interfaces) {
|
||||
types.addAll(_fetchAllTypesFromObject(i));
|
||||
}
|
||||
|
||||
return types;
|
||||
|
|
|
@ -56,8 +56,9 @@ GraphQLType _objectTypeFromDartType(Type type, [List<Type> typeArguments]) {
|
|||
GraphQLObjectType objectTypeFromClassMirror(ClassMirror mirror) {
|
||||
var fields = <GraphQLField>[];
|
||||
|
||||
for (var name in mirror.instanceMembers.keys) {
|
||||
var methodMirror = mirror.instanceMembers[name];
|
||||
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 &&
|
||||
|
@ -67,11 +68,59 @@ GraphQLObjectType objectTypeFromClassMirror(ClassMirror mirror) {
|
|||
fields.add(fieldFromGetter(name, methodMirror, exclude, mirror));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
walkMap(mirror.instanceMembers);
|
||||
|
||||
if (mirror.isAbstract) {
|
||||
var decls = <Symbol, MethodMirror>{};
|
||||
|
||||
mirror.declarations.forEach((name, decl) {
|
||||
if (decl is MethodMirror) {
|
||||
decls[name] = decl;
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
return objectType(
|
||||
MirrorSystem.getName(mirror.simpleName),
|
||||
fields: fields,
|
||||
isInterface: mirror.isAbstract,
|
||||
interfaces: inheritsFrom,
|
||||
description: _getDescription(mirror.metadata),
|
||||
);
|
||||
}
|
||||
|
@ -85,9 +134,7 @@ GraphQLEnumType enumTypeFromClassMirror(ClassMirror mirror) {
|
|||
values.add(
|
||||
new GraphQLEnumValue(
|
||||
MirrorSystem.getName(name),
|
||||
mirror
|
||||
.getField(name)
|
||||
.reflectee,
|
||||
mirror.getField(name).reflectee,
|
||||
description: _getDescription(methodMirror.metadata),
|
||||
deprecationReason: _getDeprecationReason(methodMirror.metadata),
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue