platform/graphql_schema/lib/src/field.dart

28 lines
827 B
Dart
Raw Normal View History

2018-08-02 13:31:54 +00:00
part of graphql_schema.src.schema;
typedef FutureOr<Value> GraphQLFieldResolver<Value, Serialized>(
Serialized serialized);
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>[],
this.resolve,
this.type}) {
this.arguments.addAll(arguments ?? <GraphQLFieldArgument>[]);
}
2018-08-02 13:31:54 +00:00
FutureOr<Serialized> serialize(Value value) {
return type.serialize(value);
}
FutureOr<Value> deserialize(Serialized serialized) {
if (resolve != null) return resolve(serialized);
return type.deserialize(serialized);
}
}