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
|
|
|
|
2018-08-04 19:18:53 +00:00
|
|
|
class GraphQLObjectField<Value, Serialized> {
|
|
|
|
final List<GraphQLFieldInput> inputs = <GraphQLFieldInput>[];
|
2018-08-02 13:31:54 +00:00
|
|
|
final String name;
|
|
|
|
final GraphQLFieldResolver<Value, Serialized> resolve;
|
|
|
|
final GraphQLType<Value, Serialized> type;
|
2018-08-04 19:18:53 +00:00
|
|
|
final String description;
|
2018-08-03 17:36:34 +00:00
|
|
|
final String deprecationReason;
|
2018-08-02 13:31:54 +00:00
|
|
|
|
2018-08-04 19:18:53 +00:00
|
|
|
GraphQLObjectField(this.name, this.type,
|
|
|
|
{Iterable<GraphQLFieldInput> arguments: const <GraphQLFieldInput>[],
|
2018-08-02 15:17:14 +00:00
|
|
|
@required this.resolve,
|
2018-08-04 19:18:53 +00:00
|
|
|
this.deprecationReason,
|
|
|
|
this.description}) {
|
|
|
|
assert(type != null, 'GraphQL fields must specify a `type`.');
|
|
|
|
assert(
|
|
|
|
resolve != null, 'GraphQL fields must specify a `resolve` callback.');
|
|
|
|
this.inputs.addAll(arguments ?? <GraphQLFieldInput>[]);
|
2018-08-02 13:50:31 +00:00
|
|
|
}
|
2018-08-02 13:31:54 +00:00
|
|
|
|
2018-08-03 17:36:34 +00:00
|
|
|
bool get isDeprecated => deprecationReason?.isNotEmpty == true;
|
|
|
|
|
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);
|
|
|
|
}
|
2018-08-04 19:18:53 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
bool operator ==(other) =>
|
|
|
|
other is GraphQLObjectField &&
|
|
|
|
other.name == name &&
|
|
|
|
other.deprecationReason == deprecationReason &&
|
|
|
|
other.type == type &&
|
|
|
|
other.resolve == resolve &&
|
|
|
|
const ListEquality<GraphQLFieldInput>().equals(other.inputs, inputs);
|
2018-08-02 13:31:54 +00:00
|
|
|
}
|