I want fetch data from existing graphql endpoint in java.
import static io.restassured.RestAssured.given;
import java.util.ArrayList;
import java.util.List;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
public class Universal {
static List<String> ids =new ArrayList<String>();
public static void main(String[] args) {
Query query = new Query();
query.setQuery("query universal($ids:[String!]!, $latestBy: String) {
universal(is: $ids, latestBy: $latestBy)
{ price {
requestedId
ClosePrice
}}}");
QueryVariable variable = new QueryVariable();
ids.add("98978C105");
variable.setIds(ids);
variable.setLatestBy("10");
query.setVariable(variable);
Response response = given()
.log().all()
.contentType(ContentType.JSON)
.header("Authorization", "Bearer eyJhbGciOiJSUzUxMiJ9.eyJkYXRhX2Zpcm1faWQiOjE4NCwiY2xpZW50X3VzZXJfaWQiOjcwMjYsInVzZXJfaWQiOjI0Mzg5LCJ1c2VyX25hbWUiOiJhYmhpc2hlay56dm")
.body(query)
.when()
.post("https://badjhuku52e.us-east-2.amazonaws.com/gql");
System.out.println("API response body = " + response.getBody().asString());
}
}
Here latestBy is no of outputs on those IDs. When I run this program.I got this error -
Body:
{
"query": "query universal($ids:[String!]!, $latestBy: String){universal(ids: $ids, latestBy: $latestBy) {priceData{requestedId Closeprice }}}",
"variable": {
"ids": [
"98978C105"
],
"latestBy": "10"
}
}
API response body = {"errors":[{"message":"Variable \"$ids\" of required type \"[String!]!\" was not provided.","locations":[{"line":1,"column":21}],"extensions":{"code":"INTERNAL_SERVER_ERROR","exception":{"stacktrace":["GraphQLError: Variable \"$ids\" of required type \"[String!]!\" was not provided."," at coerceVariableValues (/var/task/node_modules/graphql/execution/values.js:105:11)"," at getVariableValues (/var/task/node_modules/graphql/execution/values.js:47:21)"," at buildExecutionContext (/var/task/node_modules/graphql/execution/execute.js:280:63)"," at execute (/var/task/node_modules/graphql/execution/execute.js:116:22)"," at execute (/var/task/node_modules/apollo-server-core/dist/requestPipeline.js:206:48)"," at processGraphQLRequest (/var/task/node_modules/apollo-server-core/dist/requestPipeline.js:140:34)"," at processTicksAndRejections (internal/process/task_queues.js:95:5)"," at async processHTTPRequest (/var/task/node_modules/apollo-server-core/dist/runHttpQuery.js:187:30)"]}}}]}
In this response body part shows that my ids in the form of List and List is not null. But ERROR says completely opposite
It should be variables
not variable
as follows:
{
"query": "query universal($ids:[String!]!, $latestBy: String){universal(ids: $ids, latestBy: $latestBy) {priceData{requestedId Closeprice }}}",
"variables": {
"ids": [
"98978C105"
],
"latestBy": "10"
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.