Search in sources :

Example 1 with GraphQLClientException

use of io.smallrye.graphql.client.GraphQLClientException in project smallrye-graphql by smallrye.

the class ErrorBehavior method shouldFetchComplexError.

@Test
void shouldFetchComplexError() {
    fixture.returns("{\"errors\":[" + "{" + "\"message\":\"System error\"," + "\"locations\":[{\"line\":1,\"column\":84}]," + "\"path\":[\"order\",\"items\",0,\"product\"]" + "}" + "]," + "\"data\":{" + "\"order\":{" + "\"id\":\"o1\"," + "\"items\":[" + "{\"product\":null}," + "{\"product\":null}" + "]}}}");
    OrderApi api = fixture.build(OrderApi.class);
    GraphQLClientException throwable = catchThrowableOfType(() -> api.order("o1"), GraphQLClientException.class);
    then(fixture.query()).isEqualTo("query order($id: String!) { order(id: $id) {id orderDate items {product {id name}}} }");
    then(fixture.variables()).isEqualTo("{'id':'o1'}");
    then(throwable).hasExactlyOneErrorWhich().hasMessage("System error").hasPath("order", "items", 0, "product").hasSourceLocation(1, 84).hasErrorCode(null);
}
Also used : GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) Test(org.junit.jupiter.api.Test)

Example 2 with GraphQLClientException

use of io.smallrye.graphql.client.GraphQLClientException in project smallrye-graphql by smallrye.

the class ErrorBehavior method shouldFailToMapOuterNestedError.

@Test
void shouldFailToMapOuterNestedError() {
    fixture.returns(deeplyNestedError("{\"outer\":null}"));
    DeepErrorApi api = fixture.build(DeepErrorApi.class);
    GraphQLClientException throwable = catchThrowableOfType(api::outer, GraphQLClientException.class);
    thenDeeplyNestedErrorException(throwable);
}
Also used : GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) Test(org.junit.jupiter.api.Test)

Example 3 with GraphQLClientException

use of io.smallrye.graphql.client.GraphQLClientException in project smallrye-graphql by smallrye.

the class ErrorBehavior method shouldFailOnErrorWithNullMessage.

@Test
void shouldFailOnErrorWithNullMessage() {
    fixture.returns("{\n" + "  \"errors\": [\n" + "    {\n" + "      \"message\": null,\n" + "      \"extensions\": {\n" + "        \"classification\": \"SomeClassification\"\n" + "      }\n" + "    }\n" + "  ],\n" + "  \"data\": null\n" + "}\n");
    StringApi api = fixture.build(StringApi.class);
    GraphQLClientException thrown = catchThrowableOfType(api::greeting, GraphQLClientException.class);
    then(thrown).hasExactlyOneErrorWhich().hasMessage(null).hasNoSourceLocation().hasClassification("SomeClassification").hasErrorCode(null);
}
Also used : GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) Test(org.junit.jupiter.api.Test)

Example 4 with GraphQLClientException

use of io.smallrye.graphql.client.GraphQLClientException in project smallrye-graphql by smallrye.

the class ErrorBehavior method shouldFailOnErrorWithoutLocations.

@Test
void shouldFailOnErrorWithoutLocations() {
    fixture.returns("{\n" + "  \"errors\": [\n" + "    {\n" + "      \"message\": \"something went wrong\",\n" + "      \"extensions\": {\n" + "        \"classification\": \"SomeClassification\"\n" + "      }\n" + "    }\n" + "  ],\n" + "  \"data\": null\n" + "}\n");
    StringApi api = fixture.build(StringApi.class);
    GraphQLClientException thrown = catchThrowableOfType(api::greeting, GraphQLClientException.class);
    then(thrown).hasExactlyOneErrorWhich().hasMessage("something went wrong").hasNoSourceLocation().hasClassification("SomeClassification").hasErrorCode(null);
}
Also used : GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) Test(org.junit.jupiter.api.Test)

Example 5 with GraphQLClientException

use of io.smallrye.graphql.client.GraphQLClientException in project smallrye-graphql by smallrye.

the class ErrorBehavior method shouldFailOnErrorWithoutMessage.

@Test
void shouldFailOnErrorWithoutMessage() {
    fixture.returns("{" + "\"data\":{\"greeting\":null}," + "\"errors\":[{" + /**/
    "\"locations\":[{\"line\":1,\"column\":2,\"sourceName\":\"loc\"}]," + /**/
    "\"path\": [\"greeting\"],\n" + /**/
    "\"extensions\":{" + /**/
    "\"description\":\"some description\"," + /**/
    "\"queryPath\":[\"greeting\"]," + /**/
    "\"classification\":\"DataFetchingException\"," + /**/
    "\"code\":\"no-greeting\"}" + "}]}}");
    StringApi api = fixture.build(StringApi.class);
    GraphQLClientException thrown = catchThrowableOfType(api::greeting, GraphQLClientException.class);
    then(thrown).hasExactlyOneErrorWhich().hasMessage(null).hasSourceLocation(1, 2).hasPath("greeting").hasErrorCode("no-greeting");
}
Also used : GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) Test(org.junit.jupiter.api.Test)

Aggregations

GraphQLClientException (io.smallrye.graphql.client.GraphQLClientException)18 Test (org.junit.jupiter.api.Test)14 GraphQLError (io.smallrye.graphql.client.GraphQLError)2 InvalidResponseException (io.smallrye.graphql.client.InvalidResponseException)1 Response (io.smallrye.graphql.client.Response)1 ResponseImpl (io.smallrye.graphql.client.impl.ResponseImpl)1 ResponseReader (io.smallrye.graphql.client.impl.ResponseReader)1 JsonReader (io.smallrye.graphql.client.impl.typesafe.json.JsonReader)1 JsonUtils (io.smallrye.graphql.client.impl.typesafe.json.JsonUtils)1 JsonUtils.isListOf (io.smallrye.graphql.client.impl.typesafe.json.JsonUtils.isListOf)1 MethodInvocation (io.smallrye.graphql.client.impl.typesafe.reflection.MethodInvocation)1 ErrorOr (io.smallrye.graphql.client.typesafe.api.ErrorOr)1 StringReader (java.io.StringReader)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Collectors.joining (java.util.stream.Collectors.joining)1 Json (javax.json.Json)1 JsonArray (javax.json.JsonArray)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonException (javax.json.JsonException)1