Search in sources :

Example 16 with Document

use of io.smallrye.graphql.client.core.Document in project smallrye-graphql by smallrye.

the class VariablesTest method variablesDefaultValueTest.

@Test
public void variablesDefaultValueTest() throws IOException, URISyntaxException {
    String expectedRequest = Utils.getResourceFileContent("core/variablesDefaultValue.graphql");
    Variable varName = var("name", GQL_STRING, "Lee Byron");
    Document document = document(operation(QUERY, vars(varName), field("helloYou", arg("name", varName))));
    String generatedRequest = document.build();
    AssertGraphQL.assertEquivalentGraphQLRequest(expectedRequest, generatedRequest);
}
Also used : Variable(io.smallrye.graphql.client.core.Variable) Document(io.smallrye.graphql.client.core.Document) Test(org.junit.jupiter.api.Test)

Example 17 with Document

use of io.smallrye.graphql.client.core.Document in project smallrye-graphql by smallrye.

the class VariablesTest method variablesInInputObjectTest.

@Test
public void variablesInInputObjectTest() throws IOException, URISyntaxException {
    String expectedRequest = Utils.getResourceFileContent("core/variablesInInputObject.graphql");
    Variable varBool = var("varBool", nonNull(GQL_BOOL));
    Variable varInt = var("varInt", nonNull(GQL_INT));
    Variable varFloat = var("varFloat", nonNull(GQL_FLOAT));
    Variable varString = var("varString", nonNull(GQL_STRING));
    Variable varID = var("varID", GQL_ID);
    Document document = document(operation(QUERY, vars(varBool, varInt, varFloat, varString, varID), field("basicScalarHolder", args(arg("basicScalarHolder", inputObject(prop("bool", varBool), prop("int", varInt), prop("float", varFloat), prop("string", varString), prop("iD", varID)))), field("bool"), field("int"), field("float"), field("string"), field("iD"))));
    String generatedRequest = document.build();
    AssertGraphQL.assertEquivalentGraphQLRequest(expectedRequest, generatedRequest);
}
Also used : Variable(io.smallrye.graphql.client.core.Variable) Document(io.smallrye.graphql.client.core.Document) Test(org.junit.jupiter.api.Test)

Example 18 with Document

use of io.smallrye.graphql.client.core.Document in project quarkus-quickstarts by quarkusio.

the class StarWarsResource method getAllFilmsUsingDynamicClient.

@GET
@Path("/dynamic")
@Produces(MediaType.APPLICATION_JSON)
@Blocking
public List<Film> getAllFilmsUsingDynamicClient() throws Exception {
    Document query = document(operation(field("allFilms", field("films", field("title"), field("planetConnection", field("planets", field("name")))))));
    Response response = dynamicClient.executeSync(query);
    // translate it into an instance of the corresponding model class
    return response.getObject(FilmConnection.class, "allFilms").getFilms();
}
Also used : Response(io.smallrye.graphql.client.Response) FilmConnection(org.acme.microprofile.graphql.client.model.FilmConnection) Document(io.smallrye.graphql.client.core.Document) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Blocking(io.smallrye.common.annotation.Blocking)

Example 19 with Document

use of io.smallrye.graphql.client.core.Document 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");
}
Also used : Response(io.smallrye.graphql.client.Response) JsonArray(javax.json.JsonArray) SuperHero(examples.typesafeclient.SuperHero) Document(io.smallrye.graphql.client.core.Document)

Example 20 with Document

use of io.smallrye.graphql.client.core.Document in project smallrye-graphql by smallrye.

the class EnumsTest method enumsTest.

@Test
public void enumsTest() {
    String expectedRequest = Utils.getResourceFileContent("core/enums.graphql");
    Document document = document(operation(QUERY, field("exams", args(arg("result", gqlEnum("PASSED"))), field("score"))));
    String generatedRequest = document.build();
    AssertGraphQL.assertEquivalentGraphQLRequest(expectedRequest, generatedRequest);
}
Also used : Document(io.smallrye.graphql.client.core.Document) Test(org.junit.jupiter.api.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