upsert<_Model extends GraphqlModel> method

  1. @override
Future<Response?> upsert<_Model extends GraphqlModel>(
  1. _Model instance, {
  2. Query? query,
  3. ModelRepository<GraphqlModel>? repository,
})

Insert or update a model instance

Implementation

@override
Future<Response?> upsert<_Model extends GraphqlModel>(instance, {query, repository}) async {
  final adapter = modelDictionary.adapterFor[_Model]!;
  final variables = await adapter.toGraphql(instance, provider: this, repository: repository);
  final request = GraphqlRequest<_Model>(
    action: QueryAction.upsert,
    instance: instance,
    modelDictionary: modelDictionary,
    query: query,
    variableNamespace: variableNamespace,
    variables: variables,
  ).request;
  if (request == null) return null;
  await for (final resp in link.request(request)) {
    return resp;
  }
  return null;
}