Search in sources :

Example 1 with ApolloClient

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");
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) Test(org.junit.jupiter.api.Test)

Example 2 with ApolloClient

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))));
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) GetProductsWithFilterQuery(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) QueryConsistency(com.example.graphql.client.betterbotz.type.QueryConsistency) ProductsFilterInput(com.example.graphql.client.betterbotz.type.ProductsFilterInput) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StargateConnectionInfo(io.stargate.it.storage.StargateConnectionInfo) LoggerFactory(org.slf4j.LoggerFactory) Error(com.apollographql.apollo.api.Error) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) SimpleDateFormat(java.text.SimpleDateFormat) CompletableFuture(java.util.concurrent.CompletableFuture) ApolloClient(com.apollographql.apollo.ApolloClient) RestUtils(io.stargate.it.http.RestUtils) CustomType(com.example.graphql.client.betterbotz.type.CustomType) CqlSession(com.datastax.oss.driver.api.core.CqlSession) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) ParseException(java.text.ParseException) CustomTypeValue(com.apollographql.apollo.api.CustomTypeValue) Logger(org.slf4j.Logger) Operation(com.apollographql.apollo.api.Operation) TimeZone(java.util.TimeZone) CustomTypeAdapter(com.apollographql.apollo.api.CustomTypeAdapter) ApolloCall(com.apollographql.apollo.ApolloCall) Instant(java.time.Instant) QueryOptions(com.example.graphql.client.betterbotz.type.QueryOptions) TestKeyspace(io.stargate.it.driver.TestKeyspace) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) OkHttpClient(okhttp3.OkHttpClient) ApolloException(com.apollographql.apollo.exception.ApolloException) UuidFilterInput(com.example.graphql.client.betterbotz.type.UuidFilterInput) Response(com.apollographql.apollo.api.Response) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) Mutation(com.apollographql.apollo.api.Mutation) DeleteProductsMutation(com.example.graphql.client.betterbotz.products.DeleteProductsMutation) ApolloMutationCall(com.apollographql.apollo.ApolloMutationCall) GetProductsWithFilterQuery(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery) AfterEach(org.junit.jupiter.api.AfterEach)

Example 3 with ApolloClient

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");
}
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 4 with ApolloClient

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");
}
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 5 with ApolloClient

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);
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) Assertions.catchThrowableOfType(org.assertj.core.api.Assertions.catchThrowableOfType) MutationConsistency(com.example.graphql.client.betterbotz.type.MutationConsistency) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Error(com.apollographql.apollo.api.Error) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) InsertOrdersWithAtomicMutation(com.example.graphql.client.betterbotz.atomic.InsertOrdersWithAtomicMutation) UUID(java.util.UUID) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ApolloClient(com.apollographql.apollo.ApolloClient) OrdersInput(com.example.graphql.client.betterbotz.type.OrdersInput) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) MutationOptions(com.example.graphql.client.betterbotz.type.MutationOptions) Uuids(com.datastax.oss.driver.api.core.uuid.Uuids) ProductsAndOrdersMutation(com.example.graphql.client.betterbotz.atomic.ProductsAndOrdersMutation) InsertOrdersWithAtomicMutation(com.example.graphql.client.betterbotz.atomic.InsertOrdersWithAtomicMutation) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

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