Search in sources :

Example 11 with GraphQLClientException

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

the class ErrorBehavior method shouldFailOnValidationError.

@Test
void shouldFailOnValidationError() {
    fixture.returns("{\n" + "  \"errors\": [\n" + "    {\n" + "      \"message\": \"Validation error of type FieldUndefined: Field 'foo' in type 'Query' is undefined @ 'foo'\",\n" + "      \"locations\": [\n" + "        {\n" + "          \"line\": 1,\n" + "          \"column\": 8\n" + "        }\n" + "      ]," + "      \"extensions\": {\n" + "        \"description\": \"Field 'foo' in type 'Query' is undefined\",\n" + "        \"validationErrorType\": \"FieldUndefined\",\n" + "        \"queryPath\": [\n" + "          \"foo\"\n" + "        ],\n" + "        \"classification\": \"ValidationError\"\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("Validation error of type FieldUndefined: Field 'foo' in type 'Query' is undefined @ 'foo'").hasSourceLocation(1, 8).hasExtension("description", "Field 'foo' in type 'Query' is undefined").hasExtension("validationErrorType", "FieldUndefined").hasExtension("classification", "ValidationError").hasErrorCode(null);
}
Also used : GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) Test(org.junit.jupiter.api.Test)

Example 12 with GraphQLClientException

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

the class ErrorBehavior method shouldFailOnErrorWithEmptyLocations.

@Test
void shouldFailOnErrorWithEmptyLocations() {
    fixture.returns("{\n" + "  \"errors\": [\n" + "    {\n" + "      \"message\": \"something went wrong\",\n" + "      \"locations\": []," + "      \"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").hasSourceLocations().hasClassification("SomeClassification").hasErrorCode(null);
}
Also used : GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) Test(org.junit.jupiter.api.Test)

Example 13 with GraphQLClientException

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

the class ErrorBehavior method shouldFailOnErrorWithoutExtensions.

@Test
void shouldFailOnErrorWithoutExtensions() {
    fixture.returns("{\n" + "  \"errors\": [\n" + "    {\n" + "      \"message\": \"something went wrong\",\n" + "      \"locations\": [\n" + "        {\n" + "          \"line\": 1,\n" + "          \"column\": 8\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").hasSourceLocation(1, 8).hasErrorCode(null);
}
Also used : GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) Test(org.junit.jupiter.api.Test)

Example 14 with GraphQLClientException

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

the class ErrorBehavior method shouldFetchErrorOnNullData.

@Test
void shouldFetchErrorOnNullData() {
    fixture.returns("{" + "\"data\":null," + "\"errors\":[{" + /**/
    "\"message\":\"currently can't search for teams\"," + /**/
    "\"locations\":[{\"line\":1,\"column\":2,\"sourceName\":\"loc\"}]," + /**/
    "\"path\": [\"teams\"],\n" + /**/
    "\"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").hasPath("teams").hasSourceLocation(1, 2).hasErrorCode("team-search-disabled");
}
Also used : GraphQLClientException(io.smallrye.graphql.client.GraphQLClientException) Test(org.junit.jupiter.api.Test)

Example 15 with GraphQLClientException

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

the class ErrorBehavior method shouldFetchErrorOrWithNullInPath.

@Test
void shouldFetchErrorOrWithNullInPath() {
    fixture.returns("{" + "\"data\":{\"teams\":null}," + "\"errors\":[{" + /**/
    "\"message\":\"can't get team name\"," + /**/
    "\"locations\":[{\"line\":1,\"column\":2,\"sourceName\":\"loc\"}]," + /**/
    "\"path\": [\"teams\",\"name\"],\n" + /**/
    "\"extensions\":{" + /**/
    "\"code\":\"team-name-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("can't get team name").hasPath("teams", "name").hasSourceLocation(1, 2).hasErrorCode("team-name-disabled");
}
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