use of com.apollographql.apollo.ApolloClient in project stargate by stargate.
the class ApolloTest method invalidTypeMappingReturnsErrorResponse.
@Test
public void invalidTypeMappingReturnsErrorResponse() {
ApolloClient client = getApolloClient("/graphql/" + keyspace);
// Expected UUID format
GraphQLTestException ex = catchThrowableOfType(() -> getProduct(client, "zzz"), GraphQLTestException.class);
assertThat(ex.errors).hasSize(1);
assertThat(ex.errors.get(0).getMessage()).contains("Invalid UUID string");
}
use of com.apollographql.apollo.ApolloClient in project stargate by stargate.
the class ApolloTestBase method cleanUpProducts.
@AfterEach
public void cleanUpProducts() {
ApolloClient client = getApolloClient("/graphql/" + keyspace);
getProducts(client, 100, Optional.empty()).flatMap(GetProductsWithFilterQuery.Products::getValues).ifPresent(products -> products.forEach(p -> p.getId().ifPresent(id -> cleanupProduct(client, id))));
}
use of com.apollographql.apollo.ApolloClient in project stargate by stargate.
the class AtomicDirectiveTest method multipleOptionsWithAtomicDirectiveShouldReturnErrorResponse.
@Test
@DisplayName("Multiple options with atomic directive should return error response")
public void multipleOptionsWithAtomicDirectiveShouldReturnErrorResponse() {
ApolloClient client = getApolloClient("/graphql/" + keyspace);
ProductsAndOrdersMutation mutation = ProductsAndOrdersMutation.builder().productValue(ProductsInput.builder().id(Uuids.random().toString()).prodName("prod 1").price("1").name("prod1").created(now()).build()).productOptions(MutationOptions.builder().consistency(MutationConsistency.ALL).build()).orderValue(OrdersInput.builder().prodName("prod 1").customerName("cust 1").description("my description").build()).orderOptions(MutationOptions.builder().consistency(MutationConsistency.LOCAL_QUORUM).build()).build();
GraphQLTestException ex = catchThrowableOfType(() -> getObservable(client.mutate(mutation)), GraphQLTestException.class);
assertThat(ex).isNotNull();
assertThat(ex.errors).hasSize(2).first().extracting(Error::getMessage).asString().contains("options can only de defined once in an @atomic mutation selection");
}
use of com.apollographql.apollo.ApolloClient in project stargate by stargate.
the class AtomicDirectiveTest method multipleMutationsWithAtomicDirectiveShouldReturnErrorResponse.
@Test
@DisplayName("When invalid, multiple mutations with atomic directive should return error response")
public void multipleMutationsWithAtomicDirectiveShouldReturnErrorResponse() {
ApolloClient client = getApolloClient("/graphql/" + keyspace);
ProductsAndOrdersMutation mutation = ProductsAndOrdersMutation.builder().productValue(// The mutation is invalid as parts of the primary key are missing
ProductsInput.builder().id(UUID.randomUUID().toString()).prodName("prodName sample").customerName("customer name").build()).orderValue(OrdersInput.builder().prodName("a").customerName("b").description("c").build()).build();
GraphQLTestException ex = catchThrowableOfType(() -> getObservable(client.mutate(mutation)), GraphQLTestException.class);
assertThat(ex).isNotNull();
assertThat(ex.errors).hasSize(2).first().extracting(Error::getMessage).asString().contains("Some clustering keys are missing");
}
use of com.apollographql.apollo.ApolloClient in project stargate by stargate.
the class AtomicDirectiveTest method shouldSupportSingleMutationWithAtomicDirective.
@Test
@DisplayName("Should execute single mutation with atomic directive")
public void shouldSupportSingleMutationWithAtomicDirective() {
UUID id = UUID.randomUUID();
String productName = "prod " + id;
String description = "desc " + id;
String customer = "cust 1";
ApolloClient client = getApolloClient("/graphql/" + keyspace);
InsertOrdersWithAtomicMutation mutation = InsertOrdersWithAtomicMutation.builder().value(OrdersInput.builder().prodName(productName).customerName(customer).price("456").description(description).build()).build();
getObservable(client.mutate(mutation));
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);
}
Aggregations