A dynamic GraphQL client constructs GraphQL documents programmatically instead of deriving them from model classes or a client interface. This allows the requested operation and fields to be assembled explicitly. section 4.5.4
Building and executing a cars query
Construct a document with an operation named cars and fields such as id, manufacturer, and model. Execute it synchronously through DynamicGraphQLClient, then read the response as JSON or deserialize the cars field into List<Car>. section 4.5.4
Listing 4.29 An example cars query with a dynamic GraphQL client
// import static io.smallrye.graphql.client.core.Document.document;
// import static io.smallrye.graphql.client.core.Field.field;
// import static io.smallrye.graphql.client.core.Operation.operation;
Document cars = document(
operation("cars",
field("id"),
field("licensePlateNumber"),
field("manufacturer"),
field("model")
)
);
Shows the programmatic construction of a GraphQL document using operation and field builders. section 4.5.4
Listing 4.30 An example of request execution with a dynamic GraphQL client
DynamicGraphQLClient client = ...; // obtain a client instance Response response = client.executeSync(cars); JsonArray carsAsJson = response.getData().asJsonArray(); // or, automatically deserialize a List of cars: List<Car> cars = response.getList(Car.class, "cars");
Shows synchronous execution and two response-handling options: JSON access or typed list deserialization. section 4.5.4
