How to use the graphql query in rest API directly using java?
GraphQL String :
//Sample program
System.out.println(classname.graphqlToJson(value));
//this call will return the graphql query into formatted JSON payload and that can be directly used in REST ASSURED API for automation.
GraphQL String :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String value="query{\n" + | |
" viewer {\n" + | |
" email,\n" + | |
" }\n" + | |
"}\n"; | |
return value; | |
//Method to convert Graphql call into JSON String: | |
private static String graphqlToJson(String payload){ | |
JSONObject json = new JSONObject(); | |
json.put("query",payload); | |
return json.toString(); | |
} |
//Sample program
System.out.println(classname.graphqlToJson(value));
//this call will return the graphql query into formatted JSON payload and that can be directly used in REST ASSURED API for automation.