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();
}
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");
}
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);
}
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();
});
});
}
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);
});
}
Aggregations