Search in sources :

Example 11 with ApolloClient

use of com.apollographql.apollo.ApolloClient in project apollo-android by apollographql.

the class ResponseFetcherTest method setDefaultCachePolicy.

@Test
public void setDefaultCachePolicy() {
    ApolloClient apolloClient = ApolloClient.builder().serverUrl("http://google.com").okHttpClient(okHttpClient).defaultHttpCachePolicy(HttpCachePolicy.CACHE_ONLY).defaultResponseFetcher(NETWORK_ONLY).build();
    RealApolloCall realApolloCall = (RealApolloCall) apolloClient.query(emptyQuery);
    assertThat(realApolloCall.httpCachePolicy.fetchStrategy).isEqualTo(HttpCachePolicy.FetchStrategy.CACHE_ONLY);
    assertThat(realApolloCall.responseFetcher).isEqualTo(NETWORK_ONLY);
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) Test(org.junit.Test)

Example 12 with ApolloClient

use of com.apollographql.apollo.ApolloClient in project apollo-android by apollographql.

the class ResponseFetcherTest method defaultCacheControl.

@Test
public void defaultCacheControl() {
    ApolloClient apolloClient = ApolloClient.builder().serverUrl("http://google.com").okHttpClient(okHttpClient).build();
    RealApolloCall realApolloCall = (RealApolloCall) apolloClient.query(emptyQuery);
    assertThat(realApolloCall.httpCachePolicy.fetchStrategy).isEqualTo(HttpCachePolicy.FetchStrategy.NETWORK_ONLY);
    assertThat(realApolloCall.responseFetcher).isEqualTo(CACHE_FIRST);
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) Test(org.junit.Test)

Example 13 with ApolloClient

use of com.apollographql.apollo.ApolloClient in project stargate by stargate.

the class BulkInsertTest method bulkInsertProducts.

@Test
public void bulkInsertProducts() {
    ApolloClient client = getApolloClient("/graphql/" + keyspace);
    String productId1 = UUID.randomUUID().toString();
    String productId2 = UUID.randomUUID().toString();
    ProductsInput product1 = ProductsInput.builder().id(productId1).name("Shiny Legs").price("3199.99").created(now()).description("Normal legs but shiny.").build();
    ProductsInput product2 = ProductsInput.builder().id(productId2).name("Non-Legs").price("1000.99").created(now()).description("Non-legs.").build();
    List<BulkInsertProductsMutation.BulkInsertProduct> bulkInsertedProducts = bulkInsertProducts(client, Arrays.asList(product1, product2));
    BulkInsertProductsMutation.BulkInsertProduct firstInsertedProduct = bulkInsertedProducts.get(0);
    BulkInsertProductsMutation.BulkInsertProduct secondInsertedProduct = bulkInsertedProducts.get(1);
    assertThat(firstInsertedProduct.getApplied().get()).isTrue();
    assertThat(firstInsertedProduct.getValue()).hasValueSatisfying(value -> {
        assertThat(value.getId()).hasValue(productId1);
    });
    assertThat(secondInsertedProduct.getApplied().get()).isTrue();
    assertThat(secondInsertedProduct.getValue()).hasValueSatisfying(value -> {
        assertThat(value.getId()).hasValue(productId2);
    });
    // retrieve from db
    GetProductsWithFilterQuery.Value product1Result = getProduct(client, productId1);
    assertThat(product1Result.getId()).hasValue(productId1);
    assertThat(product1Result.getName()).hasValue(product1.name());
    assertThat(product1Result.getPrice()).hasValue(product1.price());
    assertThat(product1Result.getCreated()).hasValue(product1.created());
    assertThat(product1Result.getDescription()).hasValue(product1.description());
    GetProductsWithFilterQuery.Value product2Result = getProduct(client, productId2);
    assertThat(product2Result.getId()).hasValue(productId2);
    assertThat(product2Result.getName()).hasValue(product2.name());
    assertThat(product2Result.getPrice()).hasValue(product2.price());
    assertThat(product2Result.getCreated()).hasValue(product2.created());
    assertThat(product2Result.getDescription()).hasValue(product2.description());
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) GetProductsWithFilterQuery(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery) BulkInsertProductsMutation(com.example.graphql.client.betterbotz.products.BulkInsertProductsMutation) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) Test(org.junit.jupiter.api.Test)

Example 14 with ApolloClient

use of com.apollographql.apollo.ApolloClient in project stargate by stargate.

the class BulkInsertTest method insertOrderAndBulkInsertNProductsWithAtomic.

@Test
@DisplayName("Should execute normal insert and multiple bulk mutations with atomic directive")
public void insertOrderAndBulkInsertNProductsWithAtomic() {
    String productId1 = UUID.randomUUID().toString();
    String productId2 = UUID.randomUUID().toString();
    String productName = "Shiny Legs";
    String description = "Normal legs but shiny.";
    ProductsInput product1 = ProductsInput.builder().id(productId1).name(productName).price("3199.99").created(now()).description(description).build();
    ProductsInput product2 = ProductsInput.builder().id(productId2).name("Non-Legs").price("1000.99").created(now()).description("Non-legs.").build();
    String customerName = "c1";
    OrdersInput order = OrdersInput.builder().prodName(productName).customerName(customerName).price("3199.99").description(description).build();
    ApolloClient client = getApolloClient("/graphql/" + keyspace);
    InsertOrdersAndBulkInsertProductsWithAtomicMutation mutation = InsertOrdersAndBulkInsertProductsWithAtomicMutation.builder().values(Arrays.asList(product1, product2)).orderValue(order).build();
    insertOrdersAndBulkInsertProductsWthAtomic(client, mutation);
    GetProductsWithFilterQuery.Value product1Result = getProduct(client, productId1);
    assertThat(product1Result.getId()).hasValue(productId1);
    assertThat(product1Result.getName()).hasValue(product1.name());
    assertThat(product1Result.getPrice()).hasValue(product1.price());
    assertThat(product1Result.getCreated()).hasValue(product1.created());
    assertThat(product1Result.getDescription()).hasValue(product1.description());
    GetProductsWithFilterQuery.Value product2Result = getProduct(client, productId2);
    assertThat(product2Result.getId()).hasValue(productId2);
    assertThat(product2Result.getName()).hasValue(product2.name());
    assertThat(product2Result.getPrice()).hasValue(product2.price());
    assertThat(product2Result.getCreated()).hasValue(product2.created());
    assertThat(product2Result.getDescription()).hasValue(product2.description());
    assertThat(session.execute(SimpleStatement.newInstance("SELECT * FROM \"Orders\" WHERE \"prodName\" = ?", productName)).one()).isNotNull().extracting(r -> r.getString("\"customerName\""), r -> r.getString("description")).containsExactly(customerName, description);
}
Also used : OrdersInput(com.example.graphql.client.betterbotz.type.OrdersInput) ApolloClient(com.apollographql.apollo.ApolloClient) GetProductsWithFilterQuery(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery) Arrays(java.util.Arrays) InsertOrdersAndBulkInsertProductsWithAtomicMutation(com.example.graphql.client.betterbotz.atomic.InsertOrdersAndBulkInsertProductsWithAtomicMutation) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) UUID(java.util.UUID) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ApolloClient(com.apollographql.apollo.ApolloClient) BulkInsertProductsAndOrdersWithAtomicMutation(com.example.graphql.client.betterbotz.atomic.BulkInsertProductsAndOrdersWithAtomicMutation) OrdersInput(com.example.graphql.client.betterbotz.type.OrdersInput) ArrayList(java.util.ArrayList) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) List(java.util.List) BulkInsertProductsWithAtomicMutation(com.example.graphql.client.betterbotz.atomic.BulkInsertProductsWithAtomicMutation) BulkInsertProductsMutation(com.example.graphql.client.betterbotz.products.BulkInsertProductsMutation) GetProductsWithFilterQuery(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) InsertOrdersAndBulkInsertProductsWithAtomicMutation(com.example.graphql.client.betterbotz.atomic.InsertOrdersAndBulkInsertProductsWithAtomicMutation) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 15 with ApolloClient

use of com.apollographql.apollo.ApolloClient in project stargate by stargate.

the class BulkInsertTest method bulkInsertNProductsUsingBulkAndOrderWithAtomic.

@Test
@DisplayName("Should execute multiple mutations including bulk with atomic directive")
public void bulkInsertNProductsUsingBulkAndOrderWithAtomic() {
    String productId1 = UUID.randomUUID().toString();
    String productId2 = UUID.randomUUID().toString();
    String productName = "Shiny Legs";
    String description = "Normal legs but shiny.";
    ProductsInput product1 = ProductsInput.builder().id(productId1).name(productName).price("3199.99").created(now()).description(description).build();
    ProductsInput product2 = ProductsInput.builder().id(productId2).name("Non-Legs").price("1000.99").created(now()).description("Non-legs.").build();
    String customerName = "c1";
    OrdersInput order = OrdersInput.builder().prodName(productName).customerName(customerName).price("3199.99").description(description).build();
    ApolloClient client = getApolloClient("/graphql/" + keyspace);
    BulkInsertProductsAndOrdersWithAtomicMutation mutation = BulkInsertProductsAndOrdersWithAtomicMutation.builder().values(Arrays.asList(product1, product2)).orderValue(order).build();
    List<BulkInsertProductsAndOrdersWithAtomicMutation.Product> result = bulkInsertProductsAndOrdersWithAtomic(client, mutation).getProducts().get();
    BulkInsertProductsAndOrdersWithAtomicMutation.Product firstInsertedProduct = result.get(0);
    BulkInsertProductsAndOrdersWithAtomicMutation.Product secondInsertedProduct = result.get(1);
    assertThat(firstInsertedProduct.getApplied().get()).isTrue();
    assertThat(firstInsertedProduct.getValue()).hasValueSatisfying(value -> {
        assertThat(value.getId()).hasValue(productId1);
    });
    assertThat(secondInsertedProduct.getApplied().get()).isTrue();
    assertThat(secondInsertedProduct.getValue()).hasValueSatisfying(value -> {
        assertThat(value.getId()).hasValue(productId2);
    });
    // retrieve from db
    GetProductsWithFilterQuery.Value product1Result = getProduct(client, productId1);
    assertThat(product1Result.getId()).hasValue(productId1);
    assertThat(product1Result.getName()).hasValue(product1.name());
    assertThat(product1Result.getPrice()).hasValue(product1.price());
    assertThat(product1Result.getCreated()).hasValue(product1.created());
    assertThat(product1Result.getDescription()).hasValue(product1.description());
    GetProductsWithFilterQuery.Value product2Result = getProduct(client, productId2);
    assertThat(product2Result.getId()).hasValue(productId2);
    assertThat(product2Result.getName()).hasValue(product2.name());
    assertThat(product2Result.getPrice()).hasValue(product2.price());
    assertThat(product2Result.getCreated()).hasValue(product2.created());
    assertThat(product2Result.getDescription()).hasValue(product2.description());
    assertThat(session.execute(SimpleStatement.newInstance("SELECT * FROM \"Orders\" WHERE \"prodName\" = ?", productName)).one()).isNotNull().extracting(r -> r.getString("\"customerName\""), r -> r.getString("description")).containsExactly(customerName, description);
}
Also used : OrdersInput(com.example.graphql.client.betterbotz.type.OrdersInput) ApolloClient(com.apollographql.apollo.ApolloClient) GetProductsWithFilterQuery(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery) Arrays(java.util.Arrays) InsertOrdersAndBulkInsertProductsWithAtomicMutation(com.example.graphql.client.betterbotz.atomic.InsertOrdersAndBulkInsertProductsWithAtomicMutation) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) UUID(java.util.UUID) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ApolloClient(com.apollographql.apollo.ApolloClient) BulkInsertProductsAndOrdersWithAtomicMutation(com.example.graphql.client.betterbotz.atomic.BulkInsertProductsAndOrdersWithAtomicMutation) OrdersInput(com.example.graphql.client.betterbotz.type.OrdersInput) ArrayList(java.util.ArrayList) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) List(java.util.List) BulkInsertProductsWithAtomicMutation(com.example.graphql.client.betterbotz.atomic.BulkInsertProductsWithAtomicMutation) BulkInsertProductsMutation(com.example.graphql.client.betterbotz.products.BulkInsertProductsMutation) BulkInsertProductsAndOrdersWithAtomicMutation(com.example.graphql.client.betterbotz.atomic.BulkInsertProductsAndOrdersWithAtomicMutation) GetProductsWithFilterQuery(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

ApolloClient (com.apollographql.apollo.ApolloClient)20 Test (org.junit.jupiter.api.Test)17 ProductsInput (com.example.graphql.client.betterbotz.type.ProductsInput)14 GetProductsWithFilterQuery (com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery)10 DisplayName (org.junit.jupiter.api.DisplayName)8 OrdersInput (com.example.graphql.client.betterbotz.type.OrdersInput)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)6 Value (com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Value)6 List (java.util.List)6 UUID (java.util.UUID)6 ProductsAndOrdersMutation (com.example.graphql.client.betterbotz.atomic.ProductsAndOrdersMutation)5 DeleteProductsMutation (com.example.graphql.client.betterbotz.products.DeleteProductsMutation)5 Error (com.apollographql.apollo.api.Error)4 BulkInsertProductsMutation (com.example.graphql.client.betterbotz.products.BulkInsertProductsMutation)4 UpdateProductsMutation (com.example.graphql.client.betterbotz.products.UpdateProductsMutation)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)4 Optional (java.util.Optional)4 CompletableFuture (java.util.concurrent.CompletableFuture)4