use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.
the class RecordAsInputToDynamicClientTest method testPartial.
/**
* Try selecting only a subset of fields supported by the record.
*/
@Test
public void testPartial() throws Exception {
try (DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder().url(testingURL.toString() + "graphql").build()) {
Response response = client.executeSync("query { simple {a} }");
SimpleRecord result = response.getObject(SimpleRecord.class, "simple");
assertEquals("a", result.a());
assertNull(result.b());
}
}
use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.
the class RecordAsInputToDynamicClientTest method testReversed.
/**
* Just to be sure that if I reverse the order of fields in the query,
* they won't get mixed up on the client side.
*/
@Test
public void testReversed() throws Exception {
try (DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder().url(testingURL.toString() + "graphql").build()) {
Response response = client.executeSync("query { simple {b a} }");
SimpleRecord result = response.getObject(SimpleRecord.class, "simple");
assertEquals("a", result.a());
assertEquals("b", result.b());
}
}
use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.
the class MyClientUsage method execute.
public void execute() throws ExecutionException, InterruptedException {
Document document = document(operation(field("allHeroesIn", args(arg("location", "Outer Space")), field("name"), field("superPowers"))));
// <2>
Response response = client.executeSync(document);
// <3>
JsonArray heroesArray = response.getData().getJsonArray("allHeroesIn");
// <4>
List<SuperHero> heroes = response.getList(SuperHero.class, "allHeroesIn");
}
use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.
the class SubscriptionInitializationTimeoutTest method test.
@Test
public void test() throws ExecutionException, InterruptedException, TimeoutException {
HttpServer server = runMockServer();
try {
DynamicGraphQLClient client = new VertxDynamicGraphQLClientBuilder().subprotocols(WebsocketSubprotocol.GRAPHQL_TRANSPORT_WS).websocketInitializationTimeout(100).url("http://localhost:" + server.actualPort()).build();
Uni<Throwable> testFinish = Uni.createFrom().emitter(emitter -> {
Multi<Response> subscriptionMulti = client.subscription("{}");
subscriptionMulti.subscribe().with(item -> {
emitter.complete(null);
}, failure -> {
emitter.complete(failure);
});
});
Throwable testResult = testFinish.await().atMost(Duration.ofSeconds(3));
Assertions.assertNotNull(testResult);
Assertions.assertTrue(testResult.getMessage().contains("Server did not send a connection_ack message"), testResult.getMessage());
} finally {
server.close();
}
}
use of io.smallrye.graphql.client.Response in project smallrye-graphql by smallrye.
the class DynamicClientSingleOperationsTestBase method testSimpleQueryWithArgument.
@Test
public void testSimpleQueryWithArgument() throws ExecutionException, InterruptedException {
Document document = document(operation(field("queryWithArgument", args(arg("number", 12)), field("integer"))));
Response response = client.executeSync(document);
JsonObject data = response.getData();
assertEquals(12, data.getJsonObject("queryWithArgument").getInt("integer"));
}
Aggregations