[英]I got this error in graphql-java . {"errors":[{"message":"Variable \"$ids\" of required type \"[String!]!\" was not provided."
我想從 java 中的現有 graphql 端點獲取數據。
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());
}
}
這里 latestBy 沒有這些 ID 的輸出。 當我運行這個程序時,我得到了這個錯誤 -
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)"]}}}]}
在此響應正文部分顯示我的列表和列表形式的 id 不是 null。 但是ERROR說完全相反
它應該是variables
而不是variable
,如下所示:
{
"query": "query universal($ids:[String!]!, $latestBy: String){universal(ids: $ids, latestBy: $latestBy) {priceData{requestedId Closeprice }}}",
"variables": {
"ids": [
"98978C105"
],
"latestBy": "10"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.