The architecture is an ObjectDataSender that is a Java object for the query. This is passed into the query object, a class extending BaseGraphQLQuery. This is passed to the GraphQLRequest, which is added as the request for the endpoint. This may seem a little convoluted, but the different layers add different parts to the overall request. There are also helper methods from the WWClient class to reduce the complexity of layers.
The following code block will demonstrate the full process.
In lines 1-17, ObjectDataSenderBuilder is instantiated, passing the relevant service name. These are generally available as static variables from the org.opencode4workspace.bo class that relates to the return type, e.g. org.opencode4workspace.bo.Space.SPACES_QUERY_OBJECT_NAME. Some queries, typically those returning a Collection, will return a top-level items object, so the ObjectDataSender has a setItems method which is also exposed as a second parameter of the overloaded constructor.
Line 2 adds an argument to the query. Queries that return a Collection will typically also accept pagination arguments, e.g. BasicPaginationEnum.FIRST. When arguments (or attributes) are assigned to an ObjectDataSender, by using the relevant enum it will also validate that the correct class is passed, e.g. for the firstn elements it validates that an int is passed.
Collections will typically be used to return a subset of the results. In order to know if there are any more, and to know where the previous query stopped, you'll need to have some kind of pagination information. This can be returned by using the addPageInfo() method, as on line 3.
Then it's a case of adding the fields and children you want to retrieve. Enums are available in the relevant org.opencode4workspace.bo class, e.g. SpaceFields or SpaceChildren. Many objects will have createdBy and updatedBy children. A BasicCreatedByUpdatedByDataSender class is available to get ID, display name, photo url, and email. The constructor takes the relevant child class enum. Another ObjectDataSenderBuilder may need to be constructed to identify which fields to return for a child, as with the SpaceChildren.MEMBERS child, for Members of a Space.
Line 18 passes the ObjectDataSenderBuilder into a new instance of a class extending BaseGraphQLQuery. Classes are available for all query types and will create a default method name, e.g. "getSpaces".
Line 19 passes the query object into a new GraphQLRequest, and sets this as the request for the GraphQLEndpoint. Line 20 executes the request.
Line 21 then uses GSON to parse the result container and get the Spaces as a List. Lines 18-21 could be reduced into a single line by using a helper method from the WWClient class that takes just the new instance of a class extending BaseGraphQLQuery: