Search in sources :

Example 1 with Products

use of com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Products 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 2 with Products

use of com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Products 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)

Aggregations

ApolloClient (com.apollographql.apollo.ApolloClient)2 ApolloQueryCall (com.apollographql.apollo.ApolloQueryCall)2 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)2 ProductsAndOrdersMutation (com.example.graphql.client.betterbotz.atomic.ProductsAndOrdersMutation)2 GetOrdersByValueQuery (com.example.graphql.client.betterbotz.orders.GetOrdersByValueQuery)2 DeleteProductsMutation (com.example.graphql.client.betterbotz.products.DeleteProductsMutation)2 GetProductsWithFilterQuery (com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery)2 Products (com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Products)2 Value (com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Value)2 InsertProductsMutation (com.example.graphql.client.betterbotz.products.InsertProductsMutation)2 UpdateProductsMutation (com.example.graphql.client.betterbotz.products.UpdateProductsMutation)2 OrdersInput (com.example.graphql.client.betterbotz.type.OrdersInput)2 ProductsInput (com.example.graphql.client.betterbotz.type.ProductsInput)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2