package com.apollographql.apollo.cache.normalized;

import com.apollographql.apollo.api.ResponseField;
import com.apollographql.apollo.api.Mutation;
import com.apollographql.apollo.api.Operation;
import com.apollographql.apollo.api.Query;

import java.util.Map;

import javax.annotation.Nonnull;

/**
 * Resolves a cache key for a JSON object.
 */
public abstract class CacheKeyResolver {
  public static final CacheKeyResolver DEFAULT = new CacheKeyResolver() {
    @Nonnull @Override
    public CacheKey fromFieldRecordSet(@Nonnull ResponseField field, @Nonnull Map<String, Object> recordSet) {
      return CacheKey.NO_KEY;
    }

    @Nonnull @Override
    public CacheKey fromFieldArguments(@Nonnull ResponseField field, @Nonnull Operation.Variables variables) {
      return CacheKey.NO_KEY;
    }
  };
  public static final CacheKey QUERY_ROOT_KEY = CacheKey.from("QUERY_ROOT");
  public static final CacheKey MUTATION_ROOT_KEY = CacheKey.from("MUTATION_ROOT");

  public static CacheKey rootKeyForOperation(@Nonnull Operation operation) {
    if (operation instanceof Query) {
      return QUERY_ROOT_KEY;
    } else if (operation instanceof Mutation) {
      return MUTATION_ROOT_KEY;
    }
    throw new IllegalArgumentException("Unknown operation type.");
  }

  @Nonnull public abstract CacheKey fromFieldRecordSet(@Nonnull ResponseField field,
      @Nonnull Map<String, Object> recordSet);

  @Nonnull public abstract CacheKey fromFieldArguments(@Nonnull ResponseField field,
      @Nonnull Operation.Variables variables);
}

@@ -85,157 +85,68 @@
 api.
-ResponseField;%0Aimport com.apollographql.apollo.api.Mutation;%0Aimport com.apollographql.apollo.api.Operation;%0Aimport com.apollographql.apollo.api.Query
+Operation;%0Aimport com.apollographql.apollo.api.ResponseField
 ;%0A%0Ai
@@ -293,16 +293,95 @@
 olver %7B%0A
+  private static final CacheKey ROOT_CACHE_KEY = CacheKey.from(%22QUERY_ROOT%22);%0A%0A
   public
@@ -796,464 +796,141 @@
  %7D;%0A
+%0A
   
-public static final CacheKey QUERY_ROOT_KEY = CacheKey.from(%22QUERY_ROOT%22);%0A  public static final CacheKey MUTATION_ROOT_KEY = CacheKey.from(%22MUTATION_ROOT%22);%0A%0A  public static CacheKey rootKeyForOperation(@Nonnull Operation operation) %7B%0A    if (operation instanceof Query) %7B%0A      return QUERY_ROOT_KEY;%0A    %7D else if (operation instanceof Mutation) %7B%0A      return MUTATION_ROOT_KEY;%0A    %7D%0A    throw new IllegalArgumentException(%22Unknown operation type.%22)
+@SuppressWarnings(%22unused%22)%0A  public static CacheKey rootKeyForOperation(@Nonnull Operation operation) %7B%0A    return ROOT_CACHE_KEY
 ;%0A  

Remove mutation cache root key. (#745)