Search in sources :

Example 1 with UpdateProductsMutation

use of com.example.graphql.client.betterbotz.products.UpdateProductsMutation in project stargate by stargate.

the class ApolloTest method updateProducts.

@Test
public void updateProducts() {
    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 input = ProductsInput.builder().id(productId).name(insertInput.name()).price(insertInput.price()).created(insertInput.created()).description("Normal legs but shiny. Now available in different colors").build();
    UpdateProductsMutation mutation = UpdateProductsMutation.builder().value(input).build();
    UpdateProductsMutation.Data result = getObservable(client.mutate(mutation));
    assertThat(result.getUpdateProducts()).hasValueSatisfying(updateProducts -> {
        assertThat(updateProducts.getApplied()).hasValue(true);
        assertThat(updateProducts.getValue()).hasValueSatisfying(product -> {
            assertThat(product.getId()).hasValue(productId);
            assertThat(product.getName()).hasValue(input.name());
            assertThat(product.getPrice()).hasValue(input.price());
            assertThat(product.getCreated()).hasValue(input.created());
            assertThat(product.getDescription()).hasValue(input.description());
        });
    });
    GetProductsWithFilterQuery.Value product = getProduct(client, productId);
    assertThat(product.getId()).hasValue(productId);
    assertThat(product.getName()).hasValue(input.name());
    assertThat(product.getPrice()).hasValue(input.price());
    assertThat(product.getCreated()).hasValue(input.created());
    assertThat(product.getDescription()).hasValue(input.description());
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) UpdateProductsMutation(com.example.graphql.client.betterbotz.products.UpdateProductsMutation) GetProductsWithFilterQuery(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) Value(com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Value) Test(org.junit.jupiter.api.Test)

Example 2 with UpdateProductsMutation

use of com.example.graphql.client.betterbotz.products.UpdateProductsMutation 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();
        });
    });
}
Also used : ApolloClient(com.apollographql.apollo.ApolloClient) UpdateProductsMutation(com.example.graphql.client.betterbotz.products.UpdateProductsMutation) ProductsInput(com.example.graphql.client.betterbotz.type.ProductsInput) Test(org.junit.jupiter.api.Test)

Aggregations

ApolloClient (com.apollographql.apollo.ApolloClient)2 UpdateProductsMutation (com.example.graphql.client.betterbotz.products.UpdateProductsMutation)2 ProductsInput (com.example.graphql.client.betterbotz.type.ProductsInput)2 Test (org.junit.jupiter.api.Test)2 GetProductsWithFilterQuery (com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery)1 Value (com.example.graphql.client.betterbotz.products.GetProductsWithFilterQuery.Value)1