liveBook · Manning

Dynamic GraphQL client

As explained in Quarkus in Action

A dynamic GraphQL client is a GraphQL client that constructs GraphQL documents programmatically rather than deriving them from model classes.

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

How Quarkus in Action covers it

How deep it goes
Explains document construction and synchronous response handling, but does not detail client acquisition or configuration.
Examples
Uses a cars query requesting identifiers, license plates, manufacturers, and models.
What you can do after
Apply it via the SmallRye GraphQL client to build, execute, and decode a GraphQL request.
How it connects
Connects GraphQL queries with GraphQL clients, typesafe clients, JSON responses, and object deserialization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.