Я работаю с Java / JSON / GraphQL.
У меня есть этот GraphQL.
query GetCurrent($Partner: String, $filter: Filter, $limit: Int) {
getCurrent(
filter: $filter
limit: $limit
corporatePartner: $Partner
) {
statusCode
errorCode
errorMessage
paging {
offset
limit
count
totalCount
totalRetrievableCount
}
data {
type
key
name
total
delayed
gpsLocation {
latitude
longitude
}
}
}
}
И этот JAVA код
public void testGraphqlGetShipmentTest() throws IOException {
InputStream iStream = getShipmentListTest.class.getResourceAsStream("/graphql/getCurrentLocations.graphql");
ObjectNode variables = new ObjectMapper().createObjectNode();
variables.put("corporatePartner", "KMTUY");
variables.put("filter", "String.valueOf(filters)");
variables.put("limit", "1000");
LOGGER.debug("Read a graphql file as an input stream" + variables);
String graphqlPayload = GraphqlTemplate.parseGraphql(iStream, variables);
LOGGER.debug("Now parse the graphql file to a request payload string and Build and trigger the request");
Response response = prepareResponse(graphqlPayload);
Assert.assertEquals(response.code(), StatusCodes.OK, "Response Code Assertion");
String jsonData = response.body().string();
LOGGER.debug("Status code : " + response.code());
LOGGER.debug("Getting response : " + jsonData);
LOGGER.debug("Getting GraphQL data : " + graphqlPayload);
JsonNode jsonNode = new ObjectMapper().readTree(jsonData);
try {
Assert.assertEquals(jsonNode.get("data").get("GetCurrentLocations").get("corporatePartner").asText(), "cor1");
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Test failed! - REASON: " + jsonData);
}
}
Проблема в том, что -> variables.put("filter", "String.valueOf(filters)");
<- Если я пытаюсь создать фильтр, возникает проблема, из-за которой сервер пишет, что я не могу опубликовать строку, но карту. Если я пытаюсь создать карту, ObjectMapper показывает мне ошибки. В $ Filter у меня есть: </p>
{
"Mode": "New",
"Status": "Transit"
}
Вот ошибка:
Getting response : {"data":null,"errors":[{"cause":null,"stackTrace":[],"errorType":"ValidationError","locations":[{"line":1,"column":54,"sourceName":null}],"extensions":null,"message":"Variable 'filter' has an invalid value. Expected type 'Map' but was 'String'. Variables for input objects must be an instance of type 'Map'.","path":null,"localizedMessage":"Variable 'filter' has an invalid value. Expected type 'Map' but was 'String'. Variables for input objects must be an instance of type 'Map'.","suppressed":[]}]}
Я новичок в GraphQL.