2018-08-02 17:02:00 +00:00
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
|
|
|
import 'package:graphql_schema/graphql_schema.dart';
|
|
|
|
|
2018-08-03 23:30:19 +00:00
|
|
|
/// A GraphQL resolver that `index`es an Angel service.
|
2018-08-02 17:02:00 +00:00
|
|
|
///
|
|
|
|
/// The arguments passed to the resolver will be forwarded to service, and the
|
|
|
|
/// service will receive [Providers.graphql].
|
2018-08-03 23:30:19 +00:00
|
|
|
GraphQLFieldResolver<Value, Serialized>
|
|
|
|
resolveViaServiceIndex<Value, Serialized>(Service service,
|
|
|
|
{String idField: 'id'}) {
|
2018-08-02 17:02:00 +00:00
|
|
|
return (_, arguments) async {
|
|
|
|
var params = {'query': arguments, 'provider': Providers.graphql};
|
|
|
|
|
|
|
|
return await service.index(params) as Value;
|
|
|
|
};
|
|
|
|
}
|
2018-08-03 23:30:19 +00:00
|
|
|
|
|
|
|
/// A GraphQL resolver that `read`s a single value from an Angel service.
|
|
|
|
///
|
|
|
|
/// The arguments passed to the resolver will be forwarded to service, and the
|
|
|
|
/// service will receive [Providers.graphql].
|
|
|
|
GraphQLFieldResolver<Value, Serialized>
|
|
|
|
resolveViaServiceRead<Value, Serialized>(Service service,
|
|
|
|
{String idField: 'id'}) {
|
|
|
|
return (_, arguments) async {
|
|
|
|
var params = {'query': arguments, 'provider': Providers.graphql};
|
|
|
|
var id = arguments.remove(idField);
|
|
|
|
return await service.read(id, params) as Value;
|
|
|
|
};
|
|
|
|
}
|