Search in sources :

Example 16 with GraphQLClientException

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

the class ErrorBehavior method shouldFetchErrorOrAbsentWithoutPath.

@Test
void shouldFetchErrorOrAbsentWithoutPath() {
    fixture.returns("{" + "\"data\":{\"teams\":null}," + "\"errors\":[{" + /**/
    "\"message\":\"currently can't search for teams\"," + /**/
    "\"locations\":[{\"line\":1,\"column\":2,\"sourceName\":\"loc\"}]," + /**/
    "\"extensions\":{" + /**/
    "\"description\":\"Field 'foo' in type 'Query' is undefined\"," + /**/
    "\"validationErrorType\":\"FieldUndefined\"," + /**/
    "\"queryPath\":[\"foo\"]," + /**/
    "\"classification\":\"ValidationError\"," + /**/
    "\"code\":\"team-search-disabled\"}" + "}]}}");
    SuperHeroApi api = fixture.build(SuperHeroApi.class);
    GraphQLClientException throwable = catchThrowableOfType(api::teams, GraphQLClientException.class);
    then(fixture.query()).isEqualTo("query teams { teams {name} }");
    then(throwable).hasExactlyOneErrorWhich().hasMessage("currently can't search for teams").hasNoPath().hasSourceLocation(1, 2).hasErrorCode("team-search-disabled");
}
Also used : GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) Test(org.junit.jupiter.api.Test)

Example 17 with GraphQLClientException

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

the class ErrorBehavior method shouldFailToMapInnerNestedError.

@Test
void shouldFailToMapInnerNestedError() {
    fixture.returns(deeplyNestedError("{\"outer\":{\"inner\":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 18 with GraphQLClientException

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

the class DynamicClientErrorTest method convertToGraphQLClientException.

/**
 * Test the `ResponseImpl.throwExceptionIfErrors` method that should throw a `GraphQLClientException` if the Response
 * contains any errors.
 */
@Test
public void convertToGraphQLClientException() throws ExecutionException, InterruptedException {
    Response response = client.executeSync(document(operation(field("dummy", field("foo"), field("bar")))));
    try {
        ((ResponseImpl) response).throwExceptionIfErrors();
        fail("`throwExceptionIfErrors` call should throw a GraphQLClientException");
    } catch (GraphQLClientException e) {
        assertArrayEquals(new Object[] { "dummy", "bar" }, e.getErrors().get(0).getPath());
    }
}
Also used : Response(io.smallrye.graphql.client.Response) GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) ResponseImpl(io.smallrye.graphql.client.impl.ResponseImpl) Test(org.junit.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