Search in sources :

Example 6 with Document

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"));
}
Also used : Variable(io.smallrye.graphql.client.core.Variable) JsonObject(javax.json.JsonObject) JsonObject(javax.json.JsonObject) Document(io.smallrye.graphql.client.core.Document) Test(org.junit.Test)

Example 7 with Document

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));
}
Also used : Document(io.smallrye.graphql.client.core.Document) Test(org.junit.Test)

Example 8 with 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());
    }
}
Also used : Response(io.smallrye.graphql.client.Response) Document(io.smallrye.graphql.client.core.Document) Test(org.junit.Test)

Example 9 with Document

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));
}
Also used : Response(io.smallrye.graphql.client.Response) Calendar(java.util.Calendar) Document(io.smallrye.graphql.client.core.Document) Date(java.util.Date) Test(org.junit.Test)

Example 10 with Document

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);
}
Also used : Response(io.smallrye.graphql.client.Response) Document(io.smallrye.graphql.client.core.Document) Test(org.junit.Test)

Aggregations

Document (io.smallrye.graphql.client.core.Document)31 Test (org.junit.Test)16 Test (org.junit.jupiter.api.Test)13 Response (io.smallrye.graphql.client.Response)11 JsonObject (javax.json.JsonObject)6 Variable (io.smallrye.graphql.client.core.Variable)5 BuildException (io.smallrye.graphql.client.core.exceptions.BuildException)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 SuperHero (examples.typesafeclient.SuperHero)1 Blocking (io.smallrye.common.annotation.Blocking)1 InputObject (io.smallrye.graphql.client.core.InputObject)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 JsonArray (javax.json.JsonArray)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 FilmConnection (org.acme.microprofile.graphql.client.model.FilmConnection)1