Search in sources :

Example 31 with Record

use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.

the class ResponseNormalizationTest method testHeroNameWithVariable.

@Test
public void testHeroNameWithVariable() throws Exception {
    assertHasNoErrors("EpisodeHeroNameResponse.json", new EpisodeHeroNameQuery(Input.fromNullable(JEDI)));
    Record record = normalizedCache.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE);
    CacheReference reference = (CacheReference) record.field(TEST_FIELD_KEY_JEDI);
    assertThat(reference).isEqualTo(new CacheReference(TEST_FIELD_KEY_JEDI));
    final Record heroRecord = normalizedCache.loadRecord(reference.key(), CacheHeaders.NONE);
    assertThat(heroRecord.field("name")).isEqualTo("R2-D2");
}
Also used : EpisodeHeroNameQuery(com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery) Record(com.apollographql.apollo.cache.normalized.Record) CacheReference(com.apollographql.apollo.cache.normalized.CacheReference) Test(org.junit.Test)

Example 32 with Record

use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.

the class ResponseNormalizationTest method testSameHeroTwiceQuery.

@Test
public void testSameHeroTwiceQuery() throws Exception {
    assertHasNoErrors("SameHeroTwiceResponse.json", new SameHeroTwiceQuery());
    Record record = normalizedCache.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE);
    CacheReference heroReference = (CacheReference) record.field("hero");
    final Record hero = normalizedCache.loadRecord(heroReference.key(), CacheHeaders.NONE);
    assertThat(hero.field("name")).isEqualTo("R2-D2");
    assertThat(hero.field("appearsIn")).isEqualTo(Arrays.asList("NEWHOPE", "EMPIRE", "JEDI"));
}
Also used : Record(com.apollographql.apollo.cache.normalized.Record) CacheReference(com.apollographql.apollo.cache.normalized.CacheReference) SameHeroTwiceQuery(com.apollographql.apollo.integration.normalizer.SameHeroTwiceQuery) Test(org.junit.Test)

Example 33 with Record

use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.

the class ResponseNormalizationTest method testHeroParentTypeDependentFieldDroid.

@Test
public void testHeroParentTypeDependentFieldDroid() throws Exception {
    assertHasNoErrors("HeroParentTypeDependentFieldDroidResponse.json", new HeroParentTypeDependentFieldQuery(Input.fromNullable(JEDI)));
    Record lukeRecord = normalizedCache.loadRecord(TEST_FIELD_KEY_JEDI + ".friends.0", CacheHeaders.NONE);
    assertThat(lukeRecord.field("name")).isEqualTo("Luke Skywalker");
    assertThat(lukeRecord.field("height({\"unit\":\"METER\"})")).isEqualTo(BigDecimal.valueOf(1.72));
    final List<Object> friends = (List<Object>) normalizedCache.loadRecord(TEST_FIELD_KEY_JEDI, CacheHeaders.NONE).field("friends");
    assertThat(friends.get(0)).isEqualTo(new CacheReference(TEST_FIELD_KEY_JEDI + ".friends.0"));
    assertThat(friends.get(1)).isEqualTo(new CacheReference(TEST_FIELD_KEY_JEDI + ".friends.1"));
    assertThat(friends.get(2)).isEqualTo(new CacheReference(TEST_FIELD_KEY_JEDI + ".friends.2"));
}
Also used : HeroParentTypeDependentFieldQuery(com.apollographql.apollo.integration.normalizer.HeroParentTypeDependentFieldQuery) Record(com.apollographql.apollo.cache.normalized.Record) List(java.util.List) CacheReference(com.apollographql.apollo.cache.normalized.CacheReference) Test(org.junit.Test)

Example 34 with Record

use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.

the class ResponseNormalizationTest method testHeroAppearsInQuery.

@Test
public void testHeroAppearsInQuery() throws Exception {
    assertHasNoErrors("HeroAppearsInResponse.json", new HeroAppearsInQuery());
    Record record = normalizedCache.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE);
    CacheReference heroReference = (CacheReference) record.field("hero");
    assertThat(heroReference).isEqualTo(new CacheReference("hero"));
    final Record hero = normalizedCache.loadRecord(heroReference.key(), CacheHeaders.NONE);
    assertThat(hero.field("appearsIn")).isEqualTo(Arrays.asList("NEWHOPE", "EMPIRE", "JEDI"));
}
Also used : HeroAppearsInQuery(com.apollographql.apollo.integration.normalizer.HeroAppearsInQuery) Record(com.apollographql.apollo.cache.normalized.Record) CacheReference(com.apollographql.apollo.cache.normalized.CacheReference) Test(org.junit.Test)

Example 35 with Record

use of com.apollographql.apollo.cache.normalized.Record in project apollo-android by apollographql.

the class ResponseNormalizationTest method testHeroName.

@Test
public void testHeroName() throws Exception {
    assertHasNoErrors("HeroNameResponse.json", new HeroNameQuery());
    Record record = normalizedCache.loadRecord(QUERY_ROOT_KEY, CacheHeaders.NONE);
    CacheReference reference = (CacheReference) record.field("hero");
    assertThat(reference).isEqualTo(new CacheReference("hero"));
    final Record heroRecord = normalizedCache.loadRecord(reference.key(), CacheHeaders.NONE);
    assertThat(heroRecord.field("name")).isEqualTo("R2-D2");
}
Also used : Record(com.apollographql.apollo.cache.normalized.Record) CacheReference(com.apollographql.apollo.cache.normalized.CacheReference) EpisodeHeroNameQuery(com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery) HeroNameQuery(com.apollographql.apollo.integration.normalizer.HeroNameQuery) Test(org.junit.Test)

Aggregations

Record (com.apollographql.apollo.cache.normalized.Record)42 Test (org.junit.Test)35 CacheReference (com.apollographql.apollo.cache.normalized.CacheReference)15 NormalizedCache (com.apollographql.apollo.cache.normalized.NormalizedCache)7 Nonnull (javax.annotation.Nonnull)5 CacheKey (com.apollographql.apollo.cache.normalized.CacheKey)4 CacheHeaders (com.apollographql.apollo.cache.CacheHeaders)3 EpisodeHeroNameQuery (com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery)3 HeroAndFriendsNamesQuery (com.apollographql.apollo.integration.normalizer.HeroAndFriendsNamesQuery)3 HeroTypeDependentAliasedFieldQuery (com.apollographql.apollo.integration.normalizer.HeroTypeDependentAliasedFieldQuery)3 NonNull (android.support.annotation.NonNull)2 ApolloCacheHeaders (com.apollographql.apollo.cache.ApolloCacheHeaders)2 NormalizedCacheFactory (com.apollographql.apollo.cache.normalized.NormalizedCacheFactory)2 RecordFieldJsonAdapter (com.apollographql.apollo.cache.normalized.RecordFieldJsonAdapter)2 ApolloException (com.apollographql.apollo.exception.ApolloException)2 HeroParentTypeDependentFieldQuery (com.apollographql.apollo.integration.normalizer.HeroParentTypeDependentFieldQuery)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Set (java.util.Set)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2