![BlogImage.jpg](https://aemsimplifiedbynikhil.files.wordpress.com/2020/10/lon-blog-header.png)
Abstract
Today lets see how we can make a graphql call from our AEM Java servlet to magento server and get the response.
In my previous article we saw how to call a servlet using resourceType. So same way we will create a servlet using resourceType and add the cq:graphqlClient – (String) – default property to the resource node.
Once we are done defining the client for that resource we will go to our servlet and get the client out of the request.
GraphqlClient graphqlClient = request.getResource().adaptTo(GraphqlClient.class);
Once I have the client object in place. We will now form the query(String) using com.adobe.cq.commerce.magento.graphql.Operations API or you can always define it as a simple String.
For example, we have a below query to get country codes:
String query = Operations.query(q -> q.countries(s -> s.id())).toString();
Now we will maintain a pojo class for the type of queries that we want to execute. So as in above case we want countries code. So we will define countries getters and setters in that class. Lets say we name that class as QueryType which will have below declaration with respective getters and setters.
public class QueryType{
private JsonElement countries;
public JsonElement getCountries() {
return countries;
}
public void setCountries(JsonElement countries) {
this.countries = countries;
}
}
Read Full Blog
Q&A
Please use this thread to ask the related questions.
Kautuk Sahni