This question may have been asked before but no it was not definitively answered. How exactly does one post raw whole JSON inside the body of a Retrofit request?
See
Solved my problem based on TommySM answer (see previous). But I didn't need to make login, I used Retrofit2 for testing https GraphQL API like this:
Defined my BaseResponse class with the help of json annotations (import jackson.annotation.JsonProperty).
public class MyRequest {
@JsonProperty("query")
private String query;
@JsonProperty("operationName")
private String operationName;
@JsonProperty("variables")
private String variables;
public void setQuery(String query) {
this.query = query;
}
public void setOperationName(String operationName) {
this.operationName = operationName;
}
public void setVariables(String variables) {
this.variables = variables;
}
}
Defined the call procedure in the interface:
@POST("/api/apiname")
Call apicall(@Body RequestBody params);
Called apicall in the body of test: Create a variable of MyRequest type (for example "myLittleRequest").
Map jsonParams = convertObjectToMap(myLittleRequest);
RequestBody body =
RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),
(new JSONObject(jsonParams)).toString());
response = hereIsYourInterfaceName().apicall(body).execute();