applyPolicyToQuery method

  1. @override
Query? applyPolicyToQuery(
  1. Query? query, {
  2. OfflineFirstDeletePolicy? delete,
  3. OfflineFirstGetPolicy? get,
  4. OfflineFirstUpsertPolicy? upsert,
})

As some remote provider's may utilize an OfflineFirstPolicy from the request, this composes the policy to the query (such as in the providerArgs).

Implementation

@override
Query? applyPolicyToQuery(
  Query? query, {
  OfflineFirstDeletePolicy? delete,
  OfflineFirstGetPolicy? get,
  OfflineFirstUpsertPolicy? upsert,
}) {
  // The header value must be stringified because of how `http.Client` accepts the `headers` Map
  final headerValue = delete?.toString().split('.').last ??
      get?.toString().split('.').last ??
      upsert?.toString().split('.').last;
  return query?.copyWith(
    providerArgs: {
      ...query.providerArgs,
      'headers': {
        // This header is removed by the [RestOfflineQueueClient]
        if (headerValue != null) RestOfflineQueueClient.policyHeader: headerValue,
        ...?query.providerArgs['headers'] as Map<String, String>?,
      },
    },
  );
}