diff --git a/graphql/boot-graphql-webflux/src/main/java/com/example/graphql/controller/CustomerGraphQLController.java b/graphql/boot-graphql-webflux/src/main/java/com/example/graphql/controller/CustomerGraphQLController.java index a067fea90..9595c3e06 100644 --- a/graphql/boot-graphql-webflux/src/main/java/com/example/graphql/controller/CustomerGraphQLController.java +++ b/graphql/boot-graphql-webflux/src/main/java/com/example/graphql/controller/CustomerGraphQLController.java @@ -49,7 +49,7 @@ public Mono>> orders(List customers) { } @MutationMapping - Mono addCustomer(@Argument @NotBlank String name) { + Mono addCustomer(@Argument @NotBlank(message = "Name cant be blank") String name) { return this.customerGraphQLService.addCustomer(name); } diff --git a/graphql/boot-graphql-webflux/src/test/java/com/example/graphql/ApplicationIntegrationTest.java b/graphql/boot-graphql-webflux/src/test/java/com/example/graphql/ApplicationIntegrationTest.java index e7c314d22..b7dd280e9 100644 --- a/graphql/boot-graphql-webflux/src/test/java/com/example/graphql/ApplicationIntegrationTest.java +++ b/graphql/boot-graphql-webflux/src/test/java/com/example/graphql/ApplicationIntegrationTest.java @@ -1,5 +1,7 @@ package com.example.graphql; +import static graphql.ErrorType.ValidationError; + import com.example.graphql.common.AbstractIntegrationTest; import com.example.graphql.dtos.Customer; import com.example.graphql.dtos.CustomerDTO; @@ -20,16 +22,16 @@ void query_all_customers() { this.graphQlTester .document( """ - { - customers { - id - name - orders { - id - } - } - } - """) + query { + customers { + id + name + orders { + id + } + } + } + """) .execute() .path("customers[*]") .hasValue() @@ -42,13 +44,13 @@ void query_customers_by_name() { this.graphQlTester .document( """ - query ($name: String) { - customersByName(name: $name) { - id - name - } - } - """) + query ($name: String) { + customersByName(name: $name) { + id + name + } + } + """) .variable("name", "raja") .execute() .path("customersByName[*]") @@ -62,13 +64,13 @@ void query_insert() { String randomString = RandomStringUtils.randomAlphabetic(5); String query = """ - mutation addCustomer($cname: String) { - addCustomer(name: $cname) { - id - name - } - } - """; + mutation addCustomer($cname: String) { + addCustomer(name: $cname) { + id + name + } + } + """; this.graphQlTester .document(query) .variable("cname", randomString) @@ -81,4 +83,31 @@ mutation addCustomer($cname: String) { .entity(String.class) .isEqualTo(randomString); } + + @Test + void query_insert_failure() { + String query = + """ + mutation addCustomer($cname: String) { + addCustomer(name: $cname) { + id + name + } + } + """; + this.graphQlTester + .document(query) + .variable("cname", null) + .execute() + .errors() + .expect(error -> error.getErrorType() == ValidationError) + .verify() + .path("$.data") + .matchesJson( + """ + { + "addCustomer": null + } + """); + } }