Search in sources :

Example 6 with ApolloClient

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

the class BulkInsertTest method bulkInsertProductsWithAtomic.

@Test
public void bulkInsertProductsWithAtomic() {
    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();
    bulkInsertProductsWithAtomic(client, Arrays.asList(product1, product2));
    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) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) Test(org.junit.jupiter.api.Test)

Example 7 with ApolloClient

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

the class BulkInsertTest method bulkInsertMoreProductsThanSelectionsUsingBulkAndOrderWithAtomic.

@Test
@DisplayName("Should execute multiple mutations including bulk with more elements than selections with atomic directive")
public void bulkInsertMoreProductsThanSelectionsUsingBulkAndOrderWithAtomic() {
    String productName = "Shiny Legs";
    String description = "Normal legs but shiny.";
    List<ProductsInput> productsInputs = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        productsInputs.add(ProductsInput.builder().id(UUID.randomUUID().toString()).name(productName).price("3199.99").created(now()).description(description).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(productsInputs).orderValue(order).build();
    bulkInsertProductsAndOrdersWithAtomic(client, mutation);
    for (ProductsInput product : productsInputs) {
        GetProductsWithFilterQuery.Value product1Result = getProduct(client, (String) product.id());
        assertThat(product1Result.getId()).hasValue(product.id());
        assertThat(product1Result.getName()).hasValue(product.name());
        assertThat(product1Result.getPrice()).hasValue(product.price());
        assertThat(product1Result.getCreated()).hasValue(product.created());
        assertThat(product1Result.getDescription()).hasValue(product.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) ArrayList(java.util.ArrayList) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 8 with ApolloClient

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

the class ApolloTest method insertProducts.

@Test
public void insertProducts() {
    ApolloClient client = getApolloClient("/graphql/" + keyspace);
    String productId = UUID.randomUUID().toString();
    ProductsInput input = ProductsInput.builder().id(productId).name("Shiny Legs").price("3199.99").created(now()).description("Normal legs but shiny.").build();
    InsertProductsMutation.InsertProducts result = insertProduct(client, input);
    assertThat(result.getApplied()).hasValue(true);
    assertThat(result.getValue()).hasValueSatisfying(product -> {
        assertThat(product.getId()).hasValue(productId);
        assertThat(product.getName()).hasValue(input.name());
        assertThat(product.getPrice()).hasValue(input.price());
        assertThat(product.getCreated()).hasValue(input.created());
        assertThat(product.getDescription()).hasValue(input.description());
    });
    GetProductsWithFilterQuery.Value product = getProduct(client, productId);
    assertThat(product.getId()).hasValue(productId);
    assertThat(product.getName()).hasValue(input.name());
    assertThat(product.getPrice()).hasValue(input.price());
    assertThat(product.getCreated()).hasValue(input.created());
    assertThat(product.getDescription()).hasValue(input.description());
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) InsertProductsMutation(com.example.graphql.client.betterbotz.products.InsertProductsMutation) GetProductsWithFilterQuery(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) Value(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Value) Test(org.junit.jupiter.api.Test)

Example 9 with ApolloClient

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

the class ApolloTest method updateProducts.

@Test
public void updateProducts() {
    ApolloClient client = getApolloClient("/graphql/" + keyspace);
    String productId = UUID.randomUUID().toString();
    ProductsInput insertInput = ProductsInput.builder().id(productId).name("Shiny Legs").price("3199.99").created(now()).description("Normal legs but shiny.").build();
    insertProduct(client, insertInput);
    ProductsInput input = ProductsInput.builder().id(productId).name(insertInput.name()).price(insertInput.price()).created(insertInput.created()).description("Normal legs but shiny. Now available in different colors").build();
    UpdateProductsMutation mutation = UpdateProductsMutation.builder().value(input).build();
    UpdateProductsMutation.Data result = getObservable(client.mutate(mutation));
    assertThat(result.getUpdateProducts()).hasValueSatisfying(updateProducts -> {
        assertThat(updateProducts.getApplied()).hasValue(true);
        assertThat(updateProducts.getValue()).hasValueSatisfying(product -> {
            assertThat(product.getId()).hasValue(productId);
            assertThat(product.getName()).hasValue(input.name());
            assertThat(product.getPrice()).hasValue(input.price());
            assertThat(product.getCreated()).hasValue(input.created());
            assertThat(product.getDescription()).hasValue(input.description());
        });
    });
    GetProductsWithFilterQuery.Value product = getProduct(client, productId);
    assertThat(product.getId()).hasValue(productId);
    assertThat(product.getName()).hasValue(input.name());
    assertThat(product.getPrice()).hasValue(input.price());
    assertThat(product.getCreated()).hasValue(input.created());
    assertThat(product.getDescription()).hasValue(input.description());
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) UpdateProductsMutation(com.example.graphql.client.betterbotz.products.UpdateProductsMutation) GetProductsWithFilterQuery(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) Value(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Value) Test(org.junit.jupiter.api.Test)

Example 10 with ApolloClient

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

the class ApolloTest method getOrdersByValue.

@Test
public void getOrdersByValue() throws ExecutionException, InterruptedException {
    ApolloClient client = getApolloClient("/graphql/" + keyspace);
    OrdersInput ordersInput = OrdersInput.builder().prodName("Medium Lift Arms").build();
    GetOrdersByValueQuery query = GetOrdersByValueQuery.builder().value(ordersInput).build();
    CompletableFuture<GetOrdersByValueQuery.Data> future = new CompletableFuture<>();
    ApolloQueryCall<Optional<GetOrdersByValueQuery.Data>> observable = client.query(query);
    observable.enqueue(queryCallback(future));
    GetOrdersByValueQuery.Data result = future.get();
    observable.cancel();
    assertThat(result.getOrders()).isPresent();
    GetOrdersByValueQuery.Orders orders = result.getOrders().get();
    assertThat(orders.getValues()).isPresent();
    List<GetOrdersByValueQuery.Value> valuesList = orders.getValues().get();
    GetOrdersByValueQuery.Value value = valuesList.get(0);
    assertThat(value.getId()).hasValue("792d0a56-bb46-4bc2-bc41-5f4a94a83da9");
    assertThat(value.getProdId()).hasValue("31047029-2175-43ce-9fdd-b3d568b19bb2");
    assertThat(value.getProdName()).hasValue("Medium Lift Arms");
    assertThat(value.getCustomerName()).hasValue("Janice Evernathy");
    assertThat(value.getAddress()).hasValue("2101 Everplace Ave 3116");
    assertThat(value.getDescription()).hasValue("Ordering some more arms for my construction bot.");
    assertThat(value.getPrice()).hasValue("3199.99");
    assertThat(value.getSellPrice()).hasValue("3119.99");
}
Also used : GetOrdersByValueQuery(com.example.graphql.client.betterbotz.orders.GetOrdersByValueQuery) Optional(java.util.Optional) ApolloClient(com.apollographql.apollo.ApolloClient) OrdersInput(com.example.graphql.client.betterbotz.type.OrdersInput) CompletableFuture(java.util.concurrent.CompletableFuture) Value(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Value) Test(org.junit.jupiter.api.Test)

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