Search in sources :

Example 1 with ProductsAndOrdersMutation

use of com.example.graphql.client.betterbotz.atomic.ProductsAndOrdersMutation 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");
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) ProductsAndOrdersMutation(com.example.graphql.client.betterbotz.atomic.ProductsAndOrdersMutation) Error(com.apollographql.apollo.api.Error) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with ProductsAndOrdersMutation

use of com.example.graphql.client.betterbotz.atomic.ProductsAndOrdersMutation 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");
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) ProductsAndOrdersMutation(com.example.graphql.client.betterbotz.atomic.ProductsAndOrdersMutation) Error(com.apollographql.apollo.api.Error) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with ProductsAndOrdersMutation

use of com.example.graphql.client.betterbotz.atomic.ProductsAndOrdersMutation 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)3 ProductsAndOrdersMutation (com.example.graphql.client.betterbotz.atomic.ProductsAndOrdersMutation)3 DisplayName (org.junit.jupiter.api.DisplayName)3 Test (org.junit.jupiter.api.Test)3 Error (com.apollographql.apollo.api.Error)2 ApolloQueryCall (com.apollographql.apollo.ApolloQueryCall)1 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)1 GetOrdersByValueQuery (com.example.graphql.client.betterbotz.orders.GetOrdersByValueQuery)1 DeleteProductsMutation (com.example.graphql.client.betterbotz.products.DeleteProductsMutation)1 GetProductsWithFilterQuery (com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery)1 Products (com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Products)1 Value (com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Value)1 InsertProductsMutation (com.example.graphql.client.betterbotz.products.InsertProductsMutation)1 UpdateProductsMutation (com.example.graphql.client.betterbotz.products.UpdateProductsMutation)1 OrdersInput (com.example.graphql.client.betterbotz.type.OrdersInput)1 ProductsInput (com.example.graphql.client.betterbotz.type.ProductsInput)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1