Search in sources :

Example 16 with ApolloClient

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

the class ApolloTest method deleteProducts.

@Test
public void deleteProducts() {
    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);
    DeleteProductsMutation mutation = DeleteProductsMutation.builder().value(ProductsInput.builder().id(productId).build()).build();
    DeleteProductsMutation.Data result = getObservable(client.mutate(mutation));
    assertThat(result.getDeleteProducts()).hasValueSatisfying(deleteProducts -> {
        assertThat(deleteProducts.getApplied()).hasValue(true);
        assertThat(deleteProducts.getValue()).hasValueSatisfying(product -> {
            assertThat(product.getId()).hasValue(productId);
            assertThat(product.getName()).isEmpty();
            assertThat(product.getPrice()).isEmpty();
            assertThat(product.getCreated()).isEmpty();
            assertThat(product.getDescription()).isEmpty();
        });
    });
    List<Value> remainingProductValues = getProductValues(client, productId);
    assertThat(remainingProductValues).isEmpty();
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) DeleteProductsMutation(com.example.graphql.client.betterbotz.products.DeleteProductsMutation) Value(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Value) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) Test(org.junit.jupiter.api.Test)

Example 17 with ApolloClient

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

the class ApolloTest method queryWithPaging.

@Test
public void queryWithPaging() {
    ApolloClient client = getApolloClient("/graphql/" + keyspace);
    for (String name : Arrays.asList("a", "b", "c")) {
        insertProduct(client, ProductsInput.builder().id(UUID.randomUUID().toString()).name(name).price("1.0").created(now()).build());
    }
    List<String> names = new ArrayList<>();
    Optional<Products> products = Optional.empty();
    do {
        products = getProducts(client, 1, products.flatMap(r -> r.getPageState()));
        products.ifPresent(p -> {
            p.getValues().ifPresent(values -> {
                for (Value value : values) {
                    value.getName().ifPresent(names::add);
                }
            });
        });
    } while (products.map(p -> p.getValues().map(v -> !v.isEmpty()).orElse(false)).orElse(// Continue if there are still values
    false));
    assertThat(names).containsExactlyInAnyOrder("a", "b", "c");
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) GetProductsWithFilterQuery(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery) Arrays(java.util.Arrays) Products(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Products) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) CompletableFuture(java.util.concurrent.CompletableFuture) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ApolloClient(com.apollographql.apollo.ApolloClient) OrdersInput(com.example.graphql.client.betterbotz.type.OrdersInput) ArrayList(java.util.ArrayList) UpdateProductsMutation(com.example.graphql.client.betterbotz.products.UpdateProductsMutation) ApolloQueryCall(com.apollographql.apollo.ApolloQueryCall) ProductsAndOrdersMutation(com.example.graphql.client.betterbotz.atomic.ProductsAndOrdersMutation) Assertions.catchThrowableOfType(org.assertj.core.api.Assertions.catchThrowableOfType) InsertProductsMutation(com.example.graphql.client.betterbotz.products.InsertProductsMutation) UUID(java.util.UUID) Value(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Value) NotThreadSafe(net.jcip.annotations.NotThreadSafe) DisplayName(org.junit.jupiter.api.DisplayName) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) GetOrdersByValueQuery(com.example.graphql.client.betterbotz.orders.GetOrdersByValueQuery) List(java.util.List) Optional(java.util.Optional) DeleteProductsMutation(com.example.graphql.client.betterbotz.products.DeleteProductsMutation) Products(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Products) ArrayList(java.util.ArrayList) Value(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Value) Test(org.junit.jupiter.api.Test)

Example 18 with ApolloClient

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

the class ApolloTest method shouldSupportMultipleMutationsWithAtomicDirective.

@Test
@DisplayName("Should execute multiple mutations with atomic directive")
public void shouldSupportMultipleMutationsWithAtomicDirective() {
    UUID id = UUID.randomUUID();
    String productName = "prod " + id;
    String customer = "cust " + id;
    String price = "123";
    String description = "desc " + id;
    ApolloClient client = getApolloClient("/graphql/" + keyspace);
    ProductsAndOrdersMutation mutation = ProductsAndOrdersMutation.builder().productValue(ProductsInput.builder().id(id.toString()).prodName(productName).price(price).name(productName).customerName(customer).created(now()).description(description).build()).orderValue(OrdersInput.builder().prodName(productName).customerName(customer).price(price).description(description).build()).build();
    getObservable(client.mutate(mutation));
    assertThat(session.execute(SimpleStatement.newInstance("SELECT * FROM \"Products\" WHERE id = ?", id)).one()).isNotNull().extracting(r -> r.getString("\"prodName\""), r -> r.getString("description")).containsExactly(productName, description);
    assertThat(session.execute(SimpleStatement.newInstance("SELECT * FROM \"Orders\" WHERE \"prodName\" = ?", productName)).one()).isNotNull().extracting(r -> r.getString("\"customerName\""), r -> r.getString("description")).containsExactly(customer, description);
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) GetProductsWithFilterQuery(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery) Arrays(java.util.Arrays) Products(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Products) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) CompletableFuture(java.util.concurrent.CompletableFuture) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ApolloClient(com.apollographql.apollo.ApolloClient) OrdersInput(com.example.graphql.client.betterbotz.type.OrdersInput) ArrayList(java.util.ArrayList) UpdateProductsMutation(com.example.graphql.client.betterbotz.products.UpdateProductsMutation) ApolloQueryCall(com.apollographql.apollo.ApolloQueryCall) ProductsAndOrdersMutation(com.example.graphql.client.betterbotz.atomic.ProductsAndOrdersMutation) Assertions.catchThrowableOfType(org.assertj.core.api.Assertions.catchThrowableOfType) InsertProductsMutation(com.example.graphql.client.betterbotz.products.InsertProductsMutation) UUID(java.util.UUID) Value(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Value) NotThreadSafe(net.jcip.annotations.NotThreadSafe) DisplayName(org.junit.jupiter.api.DisplayName) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) GetOrdersByValueQuery(com.example.graphql.client.betterbotz.orders.GetOrdersByValueQuery) List(java.util.List) Optional(java.util.Optional) DeleteProductsMutation(com.example.graphql.client.betterbotz.products.DeleteProductsMutation) ProductsAndOrdersMutation(com.example.graphql.client.betterbotz.atomic.ProductsAndOrdersMutation) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 19 with ApolloClient

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

the class ApolloTest method updateProductsMissingIfExistsTrue.

@Test
public void updateProductsMissingIfExistsTrue() {
    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();
    UpdateProductsMutation mutation = UpdateProductsMutation.builder().value(input).ifExists(true).build();
    UpdateProductsMutation.Data result = getObservable(client.mutate(mutation));
    assertThat(result.getUpdateProducts()).hasValueSatisfying(products -> {
        assertThat(products.getApplied()).hasValue(false);
        assertThat(products.getValue()).hasValueSatisfying(value -> {
            assertThat(value.getId()).isEmpty();
            assertThat(value.getName()).isEmpty();
            assertThat(value.getPrice()).isEmpty();
            assertThat(value.getCreated()).isEmpty();
            assertThat(value.getDescription()).isEmpty();
        });
    });
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) UpdateProductsMutation(com.example.graphql.client.betterbotz.products.UpdateProductsMutation) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) Test(org.junit.jupiter.api.Test)

Example 20 with ApolloClient

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

the class ApolloTest method deleteProductsIfExistsTrue.

@Test
public void deleteProductsIfExistsTrue() {
    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 deleteInput = ProductsInput.builder().id(productId).name(insertInput.name()).price(insertInput.price()).created(insertInput.created()).build();
    DeleteProductsMutation mutation = DeleteProductsMutation.builder().value(deleteInput).ifExists(true).build();
    DeleteProductsMutation.Data result = getObservable(client.mutate(mutation));
    assertThat(result.getDeleteProducts()).hasValueSatisfying(deleteProducts -> {
        assertThat(deleteProducts.getApplied()).hasValue(true);
    });
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) DeleteProductsMutation(com.example.graphql.client.betterbotz.products.DeleteProductsMutation) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) 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