Add resolveFieldValue

This commit is contained in:
Tobe O 2018-08-02 09:56:00 -04:00
parent 3bf74524e0
commit e267afe85b
2 changed files with 8 additions and 4 deletions

View file

@ -1,7 +1,7 @@
part of graphql_schema.src.schema;
typedef FutureOr<Value> GraphQLFieldResolver<Value, Serialized>(
Serialized serialized);
Serialized serialized, Map<String, dynamic> argumentValues);
class GraphQLField<Value, Serialized> {
final List<GraphQLFieldArgument> arguments = <GraphQLFieldArgument>[];
@ -20,8 +20,9 @@ class GraphQLField<Value, Serialized> {
return type.serialize(value);
}
FutureOr<Value> deserialize(Serialized serialized) {
if (resolve != null) return resolve(serialized);
FutureOr<Value> deserialize(Serialized serialized,
[Map<String, dynamic> argumentValues = const <String, dynamic>{}]) {
if (resolve != null) return resolve(serialized, argumentValues);
return type.deserialize(serialized);
}
}

View file

@ -204,7 +204,10 @@ class GraphQL {
}
Future<T> resolveFieldValue<T>(GraphQLObjectType objectType, T objectValue,
String fieldName, Map<String, dynamic> argumentValues) async {}
String fieldName, Map<String, dynamic> argumentValues) async {
var field = objectType.fields.firstWhere((f) => f.name == fieldName);
return await field.resolve(objectValue, argumentValues) as T;
}
Map<String, List<SelectionContext>> collectFields(
DocumentContext document,