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');
|
print('Access graphiql at $graphiqlUri');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GraphQLDocumentation(description: 'Any object with a .text (String) property.')
|
||||||
|
abstract class HasText {
|
||||||
|
String get text;
|
||||||
|
}
|
||||||
|
|
||||||
@serializable
|
@serializable
|
||||||
@GraphQLDocumentation(
|
@GraphQLDocumentation(
|
||||||
description: 'A task that might not be completed yet. **Yay! Markdown!**')
|
description: 'A task that might not be completed yet. **Yay! Markdown!**')
|
||||||
class Todo extends Model {
|
class Todo extends Model implements HasText {
|
||||||
String text;
|
String text;
|
||||||
|
|
||||||
@GraphQLDocumentation(deprecationReason: 'Use `completion_status` instead.')
|
@GraphQLDocumentation(deprecationReason: 'Use `completion_status` instead.')
|
||||||
|
|
|
@ -427,12 +427,8 @@ List<GraphQLType> _fetchAllTypesFromObject(GraphQLObjectType objectType) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var type in objectType.interfaces) {
|
for (var i in objectType.interfaces) {
|
||||||
types.addAll(_fetchAllTypesFromObject(type));
|
types.addAll(_fetchAllTypesFromObject(i));
|
||||||
}
|
|
||||||
|
|
||||||
for (var type in objectType.possibleTypes) {
|
|
||||||
types.addAll(_fetchAllTypesFromObject(type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return types;
|
return types;
|
||||||
|
|
|
@ -56,22 +56,71 @@ GraphQLType _objectTypeFromDartType(Type type, [List<Type> typeArguments]) {
|
||||||
GraphQLObjectType objectTypeFromClassMirror(ClassMirror mirror) {
|
GraphQLObjectType objectTypeFromClassMirror(ClassMirror mirror) {
|
||||||
var fields = <GraphQLField>[];
|
var fields = <GraphQLField>[];
|
||||||
|
|
||||||
for (var name in mirror.instanceMembers.keys) {
|
void walkMap(Map<Symbol, MethodMirror> map) {
|
||||||
var methodMirror = mirror.instanceMembers[name];
|
for (var name in map.keys) {
|
||||||
var exclude = _getExclude(name, methodMirror);
|
var methodMirror = map[name];
|
||||||
var canAdd = name != #hashCode &&
|
var exclude = _getExclude(name, methodMirror);
|
||||||
name != #runtimeType &&
|
var canAdd = name != #hashCode &&
|
||||||
!methodMirror.isPrivate &&
|
name != #runtimeType &&
|
||||||
exclude?.canSerialize != true;
|
!methodMirror.isPrivate &&
|
||||||
if (methodMirror.isGetter && canAdd) {
|
exclude?.canSerialize != true;
|
||||||
fields.add(fieldFromGetter(name, methodMirror, exclude, mirror));
|
if (methodMirror.isGetter && canAdd) {
|
||||||
|
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(
|
return objectType(
|
||||||
MirrorSystem.getName(mirror.simpleName),
|
MirrorSystem.getName(mirror.simpleName),
|
||||||
fields: fields,
|
fields: fields,
|
||||||
isInterface: mirror.isAbstract,
|
isInterface: mirror.isAbstract,
|
||||||
|
interfaces: inheritsFrom,
|
||||||
description: _getDescription(mirror.metadata),
|
description: _getDescription(mirror.metadata),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -85,9 +134,7 @@ GraphQLEnumType enumTypeFromClassMirror(ClassMirror mirror) {
|
||||||
values.add(
|
values.add(
|
||||||
new GraphQLEnumValue(
|
new GraphQLEnumValue(
|
||||||
MirrorSystem.getName(name),
|
MirrorSystem.getName(name),
|
||||||
mirror
|
mirror.getField(name).reflectee,
|
||||||
.getField(name)
|
|
||||||
.reflectee,
|
|
||||||
description: _getDescription(methodMirror.metadata),
|
description: _getDescription(methodMirror.metadata),
|
||||||
deprecationReason: _getDeprecationReason(methodMirror.metadata),
|
deprecationReason: _getDeprecationReason(methodMirror.metadata),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue