subscribe<_Model extends GraphqlModel> method
Stream<List<_Model> >
subscribe<_Model extends GraphqlModel>({
- Query? query,
- ModelRepository<
GraphqlModel> ? repository,
Implementation
Stream<List<_Model>> subscribe<_Model extends GraphqlModel>(
{Query? query, ModelRepository<GraphqlModel>? repository}) async* {
final adapter = modelDictionary.adapterFor[_Model]!;
final request = GraphqlRequest<_Model>(
action: QueryAction.subscribe,
modelDictionary: modelDictionary,
query: query,
variableNamespace: variableNamespace,
).request;
if (request == null) {
yield <_Model>[];
return;
}
await for (final response in link.request(request)) {
if (response.data?.values.first is Iterable) {
final results = response.data?.values.first
.map((v) => adapter.fromGraphql(v, provider: this, repository: repository))
.toList()
.cast<Future<_Model>>();
yield await Future.wait<_Model>(results);
} else if (response.data != null) {
final result =
await adapter.fromGraphql(response.data!, provider: this, repository: repository);
yield [result as _Model];
}
}
}