使用Restassured测试Graphql查询。将查询转换为文本并以json或纯文本形式发送,但未在控制台中运行查询。但是开发人员在JS中使用Axios,需要在Java中找到相关的库来运行查询。
RequestSpecification request = given().header("Content-Type", "application/json").body(reqString);
Response response = given().config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().encodeContentTypeAs("application/graphql", ContentType.TEXT))).post("http://...");
================================================ ==========
String reqString = "mutation createNote {\n" +
"createNotePad(data:{body:\"body\",\n" +
" pinned:false,\n" +
" fileID:\"1243\"\n" +
" author:{connect:{id:\"cjok9t0i105hn08129poqmm9t\"}} \n" +
"}){id}\n" +
"}";
RequestSpecification request = given().header("Content-Type", "application/json").body(reqString);
// RequestSpecification request = given().header("Content-Type", "plain-text").body(reqString);
Response response = request.post("http://......../");
//response.prettyPrint();
System.out.println("==============");
System.out.println(response.thenReturn().asString());
System.out.println("==============");
System.out.println("Status Code in resposne:- " + response.statusCode());
String reqString = "mutation createNote {\n" +
"createNotePad(data:{body:\"body\",\n" +
" pinned:false,\n" +
" fileID:\"1243\"\n" +
" author:{connect:{id:\"cjok9t0i105hn08129poqmm9t\"}} \n" +
"}){id}\n" +
"}";
RequestSpecification request = given().header("Content-Type", "application/json").body(reqString);
它根本不运行查询。