use of io.smallrye.graphql.client.impl.ResponseImpl in project smallrye-graphql by smallrye.
the class ResponseReaderTest method testScalarsList.
@Test
public void testScalarsList() {
ResponseImpl response = ResponseReader.readFrom(EXAMPLE_RESPONSE_SCALARS_LIST, null);
assertEquals("hello", response.getList(String.class, "strings").get(0));
assertEquals("bye", response.getList(String.class, "strings").get(1));
assertEquals(32, response.getList(Long.class, "numbers").get(0));
assertEquals(33, response.getList(Long.class, "numbers").get(1));
}
use of io.smallrye.graphql.client.impl.ResponseImpl in project smallrye-graphql by smallrye.
the class ResponseReaderTest method verifyErrors.
@Test
public void verifyErrors() {
String responseString = "{\"errors\":[{\"message\":\"blabla\"," + "\"path\": [1, 2, 3, \"asd\"]," + "\"locations\": [{\"line\":1,\"column\":30}]," + "\"somethingExtra\": 123456," + "\"extensions\": {" + "\"exception\":\"EXCEPTION_EXT\"," + "\"classification\":\"CLASSIFICATION_EXT\"," + "\"code\":\"CODE_EXT\"," + "\"description\":\"DESCRIPTION_EXT\"," + "\"validationErrorType\":\"VALIDATION_ERROR_TYPE_EXT\"," + "\"queryPath\":\"QUERYPATH_EXT\"" + "}}]}";
Map<String, List<String>> headers = new HashMap<>();
headers.put("Cookie", Collections.singletonList("myCookie"));
ResponseImpl response = ResponseReader.readFrom(responseString, headers);
GraphQLError theError = response.getErrors().get(0);
assertEquals("blabla", theError.getMessage());
assertEquals(123456L, theError.getOtherFields().get("somethingExtra"));
assertEquals("EXCEPTION_EXT", theError.getException());
assertEquals("CLASSIFICATION_EXT", theError.getClassification());
assertEquals("CODE_EXT", theError.getCode());
assertEquals("DESCRIPTION_EXT", theError.getDescription());
assertEquals("VALIDATION_ERROR_TYPE_EXT", theError.getValidationErrorType());
assertEquals("QUERYPATH_EXT", theError.getQueryPath());
assertEquals(1, theError.getLocations().get(0).get("line"));
assertEquals(30, theError.getLocations().get(0).get("column"));
assertArrayEquals(new Object[] { 1, 2, 3, "asd" }, theError.getPath());
assertEquals(response.getHeaders().get("Cookie").get(0), "myCookie");
}
use of io.smallrye.graphql.client.impl.ResponseImpl in project smallrye-graphql by smallrye.
the class ResponseReaderTest method testScalars.
@Test
public void testScalars() {
ResponseImpl response = ResponseReader.readFrom(EXAMPLE_RESPONSE_SCALARS, null);
assertEquals("hello", response.getObject(String.class, "string"));
assertEquals(32, response.getObject(Long.class, "number"));
}
use of io.smallrye.graphql.client.impl.ResponseImpl 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());
}
}
Aggregations