Search in sources :

Example 1 with UnmodifiableMapBuilder

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

the class CacheKeyForFieldTest method testFieldWithNestedObjectAndVariables.

@Test
public void testFieldWithNestedObjectAndVariables() {
    // noinspection unchecked
    Map<String, Object> arguments = new UnmodifiableMapBuilder<String, Object>(1).put("episode", "JEDI").put("nested", new UnmodifiableMapBuilder<String, Object>(2).put("foo", new UnmodifiableMapBuilder<String, Object>(2).put("kind", "Variable").put("variableName", "stars").build()).put("bar", "2").build()).build();
    ResponseField field = createResponseField("hero", "hero", arguments);
    Operation.Variables variables = new Operation.Variables() {

        @Nonnull
        @Override
        public Map<String, Object> valueMap() {
            HashMap<String, Object> map = new HashMap<>();
            map.put("stars", 1);
            return map;
        }
    };
    assertThat(field.cacheKey(variables)).isEqualTo("hero({\"episode\":\"JEDI\",\"nested\":{\"bar\":\"2\",\"foo\":1}})");
}
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 2 with UnmodifiableMapBuilder

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

the class CacheKeyForFieldTest method testFieldWithArgumentAndAlias.

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

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

Example 3 with UnmodifiableMapBuilder

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

the class CacheKeyForFieldTest method testFieldWithVariableArgument.

@Test
public void testFieldWithVariableArgument() {
    // 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", Episode.JEDI);
            return map;
        }
    };
    assertThat(field.cacheKey(variables)).isEqualTo("hero({\"episode\":\"JEDI\"})");
}
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 4 with UnmodifiableMapBuilder

use of com.apollographql.apollo.api.internal.UnmodifiableMapBuilder 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 5 with UnmodifiableMapBuilder

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

the class CacheKeyForFieldTest method testFieldWithArgument.

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

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

Aggregations

ResponseField (com.apollographql.apollo.api.ResponseField)6 UnmodifiableMapBuilder (com.apollographql.apollo.api.internal.UnmodifiableMapBuilder)6 Test (org.junit.Test)6 Operation (com.apollographql.apollo.api.Operation)5 HashMap (java.util.HashMap)4 ResponseReader (com.apollographql.apollo.api.ResponseReader)1 RealResponseReader (com.apollographql.apollo.internal.response.RealResponseReader)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Map (java.util.Map)1