2018-08-02 13:31:54 +00:00
|
|
|
part of graphql_schema.src.schema;
|
|
|
|
|
|
|
|
typedef FutureOr<Value> GraphQLFieldResolver<Value, Serialized>(
|
2018-08-02 13:56:00 +00:00
|
|
|
Serialized serialized, Map<String, dynamic> argumentValues);
|
2018-08-02 13:31:54 +00:00
|
|
|
|
|
|
|
class GraphQLField<Value, Serialized> {
|
2018-08-02 13:50:31 +00:00
|
|
|
final List<GraphQLFieldArgument> arguments = <GraphQLFieldArgument>[];
|
2018-08-02 13:31:54 +00:00
|
|
|
final String name;
|
|
|
|
final GraphQLFieldResolver<Value, Serialized> resolve;
|
|
|
|
final GraphQLType<Value, Serialized> type;
|
|
|
|
|
2018-08-02 13:50:31 +00:00
|
|
|
GraphQLField(this.name,
|
|
|
|
{Iterable<GraphQLFieldArgument> arguments: const <GraphQLFieldArgument>[],
|
2018-08-02 15:17:14 +00:00
|
|
|
@required this.resolve,
|
2018-08-02 13:50:31 +00:00
|
|
|
this.type}) {
|
|
|
|
this.arguments.addAll(arguments ?? <GraphQLFieldArgument>[]);
|
|
|
|
}
|
2018-08-02 13:31:54 +00:00
|
|
|
|
|
|
|
FutureOr<Serialized> serialize(Value value) {
|
|
|
|
return type.serialize(value);
|
|
|
|
}
|
|
|
|
|
2018-08-02 13:56:00 +00:00
|
|
|
FutureOr<Value> deserialize(Serialized serialized,
|
|
|
|
[Map<String, dynamic> argumentValues = const <String, dynamic>{}]) {
|
|
|
|
if (resolve != null) return resolve(serialized, argumentValues);
|
2018-08-02 13:31:54 +00:00
|
|
|
return type.deserialize(serialized);
|
|
|
|
}
|
|
|
|
}
|