use of com.apollographql.apollo.cache.normalized.CacheReference in project apollo-android by apollographql.
the class ResponseNormalizationTest method testHeroAndFriendsNamesQueryWithIDs.
@Test
public void testHeroAndFriendsNamesQueryWithIDs() throws Exception {
assertHasNoErrors("HeroAndFriendsNameWithIdsResponse.json", new HeroAndFriendsNamesWithIDsQuery(Input.fromNullable(JEDI)));
Record record = normalizedCache.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE);
CacheReference heroReference = (CacheReference) record.field(TEST_FIELD_KEY_JEDI);
assertThat(heroReference).isEqualTo(new CacheReference("2001"));
final Record heroRecord = normalizedCache.loadRecord(heroReference.key(), CacheHeaders.NONE);
assertThat(heroRecord.field("name")).isEqualTo("R2-D2");
assertThat(heroRecord.field("friends")).isEqualTo(Arrays.asList(new CacheReference("1000"), new CacheReference("1002"), new CacheReference("1003")));
final Record luke = normalizedCache.loadRecord("1000", CacheHeaders.NONE);
assertThat(luke.field("name")).isEqualTo("Luke Skywalker");
}
use of com.apollographql.apollo.cache.normalized.CacheReference in project apollo-android by apollographql.
the class ResponseNormalizationTest method testHeroAndFriendsNamesWithIDForParentOnly.
@Test
public void testHeroAndFriendsNamesWithIDForParentOnly() throws Exception {
assertHasNoErrors("HeroAndFriendsNameWithIdsParentOnlyResponse.json", new HeroAndFriendsNamesWithIDForParentOnlyQuery(Input.fromNullable(JEDI)));
Record record = normalizedCache.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE);
CacheReference heroReference = (CacheReference) record.field(TEST_FIELD_KEY_JEDI);
assertThat(heroReference).isEqualTo(new CacheReference("2001"));
final Record heroRecord = normalizedCache.loadRecord(heroReference.key(), CacheHeaders.NONE);
assertThat(heroRecord.field("name")).isEqualTo("R2-D2");
assertThat(heroRecord.field("friends")).isEqualTo(Arrays.asList(new CacheReference("2001.friends.0"), new CacheReference("2001.friends.1"), new CacheReference("2001.friends.2")));
final Record luke = normalizedCache.loadRecord("2001.friends.0", CacheHeaders.NONE);
assertThat(luke.field("name")).isEqualTo("Luke Skywalker");
}
use of com.apollographql.apollo.cache.normalized.CacheReference in project apollo-android by apollographql.
the class ResponseNormalizationTest method testHeroAndFriendsNamesQueryWithoutIDs.
@Test
public void testHeroAndFriendsNamesQueryWithoutIDs() throws Exception {
assertHasNoErrors("HeroAndFriendsNameResponse.json", new HeroAndFriendsNamesQuery(Input.fromNullable(JEDI)));
Record record = normalizedCache.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE);
CacheReference heroReference = (CacheReference) record.field(TEST_FIELD_KEY_JEDI);
assertThat(heroReference).isEqualTo(new CacheReference(TEST_FIELD_KEY_JEDI));
final Record heroRecord = normalizedCache.loadRecord(heroReference.key(), CacheHeaders.NONE);
assertThat(heroRecord.field("name")).isEqualTo("R2-D2");
assertThat(heroRecord.field("friends")).isEqualTo(Arrays.asList(new CacheReference(TEST_FIELD_KEY_JEDI + ".friends.0"), new CacheReference(TEST_FIELD_KEY_JEDI + ".friends.1"), new CacheReference(TEST_FIELD_KEY_JEDI + ".friends.2")));
final Record luke = normalizedCache.loadRecord(TEST_FIELD_KEY_JEDI + ".friends.0", CacheHeaders.NONE);
assertThat(luke.field("name")).isEqualTo("Luke Skywalker");
}
use of com.apollographql.apollo.cache.normalized.CacheReference in project apollo-android by apollographql.
the class ResponseNormalizationTest method testHeroParentTypeDependentAliasedFieldQueryHuman.
@Test
public void testHeroParentTypeDependentAliasedFieldQueryHuman() throws Exception {
assertHasNoErrors("HeroTypeDependentAliasedFieldResponseHuman.json", new HeroTypeDependentAliasedFieldQuery(Input.fromNullable(EMPIRE)));
Record record = normalizedCache.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE);
CacheReference heroReference = (CacheReference) record.field(TEST_FIELD_KEY_EMPIRE);
final Record hero = normalizedCache.loadRecord(heroReference.key(), CacheHeaders.NONE);
assertThat(hero.field("homePlanet")).isEqualTo("Tatooine");
assertThat(hero.field("__typename")).isEqualTo("Human");
}
use of com.apollographql.apollo.cache.normalized.CacheReference in project apollo-android by apollographql.
the class ResponseNormalizer method didResolveObject.
@Override
public void didResolveObject(ResponseField field, Optional<R> objectSource) {
path = pathStack.pop();
if (objectSource.isPresent()) {
Record completedRecord = currentRecordBuilder.build();
valueStack.push(new CacheReference(completedRecord.key()));
dependentKeys.add(completedRecord.key());
recordSet.merge(completedRecord);
}
currentRecordBuilder = recordStack.pop().toBuilder();
}
Aggregations