Add resolveFieldValue
This commit is contained in:
parent
3bf74524e0
commit
e267afe85b
2 changed files with 8 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue