Search in sources :

Example 21 with ResponseField

use of com.apollographql.apollo.api.ResponseField in project apollo-android by apollographql.

the class CacheKeyForFieldTest method testFieldWithNoArguments.

@Test
public void testFieldWithNoArguments() {
    ResponseField field = ResponseField.forString("hero", "hero", null, false, Collections.<ResponseField.Condition>emptyList());
    Operation.Variables variables = new Operation.Variables() {

        @Nonnull
        @Override
        public Map<String, Object> valueMap() {
            return super.valueMap();
        }
    };
    assertThat(field.cacheKey(variables)).isEqualTo("hero");
}
Also used : ResponseField(com.apollographql.apollo.api.ResponseField) Operation(com.apollographql.apollo.api.Operation) Test(org.junit.Test)

Example 22 with ResponseField

use of com.apollographql.apollo.api.ResponseField in project apollo-android by apollographql.

the class CacheKeyForFieldTest method testFieldWithMultipleArgumentsOrderIndependent.

@Test
public void testFieldWithMultipleArgumentsOrderIndependent() {
    // noinspection unchecked
    Map<String, Object> arguments = new UnmodifiableMapBuilder<String, Object>(1).put("episode", "JEDI").put("color", "blue").build();
    ResponseField field = createResponseField("hero", "hero", arguments);
    Operation.Variables variables = new Operation.Variables() {

        @Nonnull
        @Override
        public Map<String, Object> valueMap() {
            return super.valueMap();
        }
    };
    // noinspection unchecked
    Map<String, Object> fieldTwoArguments = new UnmodifiableMapBuilder<String, Object>(1).put("color", "blue").put("episode", "JEDI").build();
    ResponseField fieldTwo = createResponseField("hero", "hero", fieldTwoArguments);
    assertThat(fieldTwo.cacheKey(variables)).isEqualTo(field.cacheKey(variables));
}
Also used : ResponseField(com.apollographql.apollo.api.ResponseField) Operation(com.apollographql.apollo.api.Operation) Test(org.junit.Test)

Example 23 with ResponseField

use of com.apollographql.apollo.api.ResponseField in project apollo-android by apollographql.

the class CacheKeyForFieldTest method testFieldWithNoArgumentsWithAlias.

@Test
public void testFieldWithNoArgumentsWithAlias() {
    ResponseField field = ResponseField.forString("r2", "hero", null, false, Collections.<ResponseField.Condition>emptyList());
    Operation.Variables variables = new Operation.Variables() {

        @Nonnull
        @Override
        public Map<String, Object> valueMap() {
            return super.valueMap();
        }
    };
    assertThat(field.cacheKey(variables)).isEqualTo("hero");
}
Also used : ResponseField(com.apollographql.apollo.api.ResponseField) Operation(com.apollographql.apollo.api.Operation) Test(org.junit.Test)

Example 24 with ResponseField

use of com.apollographql.apollo.api.ResponseField in project apollo-android by apollographql.

the class CacheKeyForFieldTest method testFieldWithVariableArgumentNull.

@Test
public void testFieldWithVariableArgumentNull() {
    // noinspection unchecked
    UnmodifiableMapBuilder<String, Object> argument = new UnmodifiableMapBuilder<String, Object>(1).put("episode", new UnmodifiableMapBuilder<String, Object>(2).put("kind", "Variable").put("variableName", "episode").build());
    ResponseField field = createResponseField("hero", "hero", argument.build());
    Operation.Variables variables = new Operation.Variables() {

        @Nonnull
        @Override
        public Map<String, Object> valueMap() {
            HashMap<String, Object> map = new HashMap<>();
            map.put("episode", null);
            return map;
        }
    };
    assertThat(field.cacheKey(variables)).isEqualTo("hero({\"episode\":null})");
}
Also used : ResponseField(com.apollographql.apollo.api.ResponseField) HashMap(java.util.HashMap) Operation(com.apollographql.apollo.api.Operation) UnmodifiableMapBuilder(com.apollographql.apollo.api.internal.UnmodifiableMapBuilder) Test(org.junit.Test)

Example 25 with ResponseField

use of com.apollographql.apollo.api.ResponseField in project apollo-android by apollographql.

the class CacheKeyForFieldTest method testFieldWithMultipleArgument.

@Test
public void testFieldWithMultipleArgument() {
    // noinspection unchecked
    Map<String, Object> build = new UnmodifiableMapBuilder<String, Object>(1).put("episode", "JEDI").put("color", "blue").build();
    ResponseField field = createResponseField("hero", "hero", build);
    Operation.Variables variables = new Operation.Variables() {

        @Nonnull
        @Override
        public Map<String, Object> valueMap() {
            return super.valueMap();
        }
    };
    assertThat(field.cacheKey(variables)).isEqualTo("hero({\"color\":\"blue\",\"episode\":\"JEDI\"})");
}
Also used : ResponseField(com.apollographql.apollo.api.ResponseField) Operation(com.apollographql.apollo.api.Operation) Test(org.junit.Test)

Aggregations

ResponseField (com.apollographql.apollo.api.ResponseField)34 Test (org.junit.Test)33 HashMap (java.util.HashMap)25 Map (java.util.Map)23 ResponseReader (com.apollographql.apollo.api.ResponseReader)13 RealResponseReader (com.apollographql.apollo.internal.response.RealResponseReader)13 Operation (com.apollographql.apollo.api.Operation)11 UnmodifiableMapBuilder (com.apollographql.apollo.api.internal.UnmodifiableMapBuilder)6 Arrays.asList (java.util.Arrays.asList)3 List (java.util.List)3 CacheKeyResolver (com.apollographql.apollo.cache.normalized.CacheKeyResolver)1 NormalizedCacheFactory (com.apollographql.apollo.cache.normalized.NormalizedCacheFactory)1 LruNormalizedCacheFactory (com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory)1 ApolloSqlHelper (com.apollographql.apollo.cache.normalized.sql.ApolloSqlHelper)1 SqlNormalizedCacheFactory (com.apollographql.apollo.cache.normalized.sql.SqlNormalizedCacheFactory)1 WebSocketSubscriptionTransport (com.apollographql.apollo.subscription.WebSocketSubscriptionTransport)1 Nonnull (javax.annotation.Nonnull)1 OkHttpClient (okhttp3.OkHttpClient)1