Implementing GraphQL queries
Both the queries we introduced in the schema in the previous section are straightforward. You pass a product ID to find a product identified by that ID – that’s the product query for you. Next, you pass the optional product criteria to find the products based on the given criteria; otherwise, products are returned based on the default values of the fields of product criteria.
In REST, you implemented the controller class in the Implementing the OAS code interfaces section of Chapter 3, API Specifications and Implementation. You created a controller, passed the call to the service, and the service called the repository to fetch the data from the database. You are going to use the same design. However, you are going to use ConcurrentHashMap
in place of the database to simplify the code. This can also be used in your automated tests.
Let’s create a repository class for that, as shown in the next code block:
public interface Repository...