use of io.smallrye.graphql.client.core.Document in project smallrye-graphql by smallrye.
the class DynamicClientSingleOperationsTestBase method testQueryWithVars.
@Test
public void testQueryWithVars() throws ExecutionException, InterruptedException {
Variable var = var("x", ScalarType.GQL_INT);
Document document = document(operation(vars(var), field(// query name
"queryWithArgument", // the query has a 'number' parameter
args(arg("number", var)), // field we want to retrieve
field("integer"))));
Map<String, Object> variableValues = Collections.singletonMap("x", 12345);
JsonObject data = client.executeSync(document, variableValues).getData();
assertEquals(12345, data.getJsonObject("queryWithArgument").getInt("integer"));
}
use of io.smallrye.graphql.client.core.Document in project smallrye-graphql by smallrye.
the class DynamicClientFragmentTest method testNamedFragment.
@Test
public void testNamedFragment() throws ExecutionException, InterruptedException {
Document document = document(operation(field("vehicles", field("wheelsCount"), fragmentRef("bicycleFields"), fragmentRef("carFields"))), fragment("bicycleFields").on("Bicycle", field("frameSize")), fragment("carFields").on("Car", field("engineCylinders")));
validateResponse(client.executeSync(document));
}
use of io.smallrye.graphql.client.core.Document in project smallrye-graphql by smallrye.
the class AbstractDynamicClientSubscriptionTest method testCounting.
@Test
public void testCounting() {
Document document = document(operation(OperationType.SUBSCRIPTION, field("countToFive")));
List<Response> responses = client.subscription(document).subscribe().asStream().collect(Collectors.toList());
for (int i = 0; i < 5; i++) {
Response response = responses.get(i);
assertEquals(i, response.getData().getInt("countToFive"));
assertNoErrors(response.getErrors());
}
}
use of io.smallrye.graphql.client.core.Document in project smallrye-graphql by smallrye.
the class DynamicClientFormatAnnotationsTest method testParsingDateWithJsonbFormatAnnotation.
/**
* Test parsing a date formatted using a @JsonbDateFormat annotation
*/
@Test
public void testParsingDateWithJsonbFormatAnnotation() throws ExecutionException, InterruptedException {
Document document = document(operation(field("something", field("dateWithJsonbAnnotation"))));
Response response = client.executeSync(document);
ObjectWithFormattedFields objectWithFormattedFields = response.getObject(ObjectWithFormattedFields.class, "something");
Date parsedDate = objectWithFormattedFields.getDateWithJsonbAnnotation();
Calendar calendar = toCalendar(parsedDate);
assertEquals(Calendar.MAY, calendar.get(Calendar.MONTH));
assertEquals(13, calendar.get(Calendar.DAY_OF_MONTH));
assertEquals(1997, calendar.get(Calendar.YEAR));
}
use of io.smallrye.graphql.client.core.Document in project smallrye-graphql by smallrye.
the class DynamicClientFormatAnnotationsTest method testParsingLongWithCustomFormat.
/**
* Test parsing a long formatted using a @NumberFormat annotation
*/
@Test
public void testParsingLongWithCustomFormat() throws ExecutionException, InterruptedException {
Document document = document(operation(field("something", field("longNumber"))));
Response response = client.executeSync(document);
ObjectWithFormattedFields objectWithFormattedFields = response.getObject(ObjectWithFormattedFields.class, "something");
Long parsedNumber = objectWithFormattedFields.getLongNumber();
assertEquals((Long) 123456789L, parsedNumber);
}
Aggregations