use of graphql.ExecutionResult in project nextprot-api by calipho-sib.
the class GraphQlExecutorImpl method executeRequest.
@Override
public Object executeRequest(Map requestBody) {
ExecutionResult executionResult = graphQL.execute((String) requestBody.get("query"));
HashMap result = new LinkedHashMap<String, Object>();
if (executionResult.getErrors().size() > 0) {
result.put("errors", executionResult.getErrors());
// log.error("Errors: {}", executionResult.getErrors());
}
result.put("data", executionResult.getData());
return result;
}
use of graphql.ExecutionResult in project OpenTripPlanner by opentripplanner.
the class GraphIndexTest method testGraphQLNested.
public void testGraphQLNested() {
String query = "query Agency{\n" + " viewer {" + " agency(id: \"agency\"){\n" + " name\n" + " routes{\n" + " shortName" + " }" + " }}\n" + "}\n";
ExecutionResult result = graph.index.graphQL.execute(query);
assertTrue(result.getErrors().isEmpty());
Map<String, Object> data = (Map<String, Object>) result.getData();
assertEquals(18, ((List) ((Map) ((Map) data.get("viewer")).get("agency")).get("routes")).size());
}
use of graphql.ExecutionResult in project OpenTripPlanner by opentripplanner.
the class GraphIndexTest method testGraphQLSimple.
public void testGraphQLSimple() {
String query = "query Agency{" + " agency(id: \"agency\"){" + " name" + " }" + "}";
ExecutionResult result = graph.index.graphQL.execute(query);
assertTrue(result.getErrors().isEmpty());
Map<String, Object> data = (Map<String, Object>) result.getData();
assertEquals("Fake Agency", ((Map) data.get("agency")).get("name"));
}
use of graphql.ExecutionResult in project OpenTripPlanner by opentripplanner.
the class GraphIndexTest method testGraphQLIntrospectionQuery.
public void testGraphQLIntrospectionQuery() {
String query = " query IntrospectionQuery {\n" + " __schema {\n" + " queryType { name }\n" + " mutationType { name }\n" + " types {\n" + " ...FullType\n" + " }\n" + " directives {\n" + " name\n" + " description\n" + " args {\n" + " ...InputValue\n" + " }\n" + " onOperation\n" + " onFragment\n" + " onField\n" + " }\n" + " }\n" + " }\n" + "\n" + " fragment FullType on __Type {\n" + " kind\n" + " name\n" + " description\n" + " fields {\n" + " name\n" + " description\n" + " args {\n" + " ...InputValue\n" + " }\n" + " type {\n" + " ...TypeRef\n" + " }\n" + " isDeprecated\n" + " deprecationReason\n" + " }\n" + " inputFields {\n" + " ...InputValue\n" + " }\n" + " interfaces {\n" + " ...TypeRef\n" + " }\n" + " enumValues {\n" + " name\n" + " description\n" + " isDeprecated\n" + " deprecationReason\n" + " }\n" + " possibleTypes {\n" + " ...TypeRef\n" + " }\n" + " }\n" + "\n" + " fragment InputValue on __InputValue {\n" + " name\n" + " description\n" + " type { ...TypeRef }\n" + " defaultValue\n" + " }\n" + "\n" + " fragment TypeRef on __Type {\n" + " kind\n" + " name\n" + " ofType {\n" + " kind\n" + " name\n" + " ofType {\n" + " kind\n" + " name\n" + " ofType {\n" + " kind\n" + " name\n" + " }\n" + " }\n" + " }\n" + " }";
ExecutionResult result = graph.index.graphQL.execute(query);
assertTrue(result.getErrors().isEmpty());
}
use of graphql.ExecutionResult in project carbon-apimgt by wso2.
the class QueryAnalyzer method analyseQueryDepth.
/**
* This method analyses the query depth.
*
* @param maxQueryDepth maximum query depth
* @param payload payload of the request
* @return true, if the query depth does not exceed the maximum value or false, if query depth exceeds the maximum
*/
public QueryAnalyzerResponseDTO analyseQueryDepth(int maxQueryDepth, String payload) {
if (log.isDebugEnabled()) {
log.debug("Analyzing query depth for " + payload + " and max query depth:" + maxQueryDepth);
}
QueryAnalyzerResponseDTO queryAnalyzerResponseDTO = new QueryAnalyzerResponseDTO();
// If maxQueryDepth is a positive value, perform the depth limitation check. Otherwise, bypass the check.
if (maxQueryDepth > 0) {
MaxQueryDepthInstrumentation maxQueryDepthInstrumentation = new MaxQueryDepthInstrumentation(maxQueryDepth);
GraphQL runtime = GraphQL.newGraphQL(schema).instrumentation(maxQueryDepthInstrumentation).build();
ExecutionResult executionResult = runtime.execute(payload);
List<GraphQLError> errors = executionResult.getErrors();
if (errors.size() > 0) {
for (GraphQLError error : errors) {
queryAnalyzerResponseDTO.addErrorToList((error.getMessage()));
}
// TODO: https://github.com/wso2/carbon-apimgt/issues/8147
queryAnalyzerResponseDTO.getErrorList().removeIf(s -> s.contains("non-nullable"));
if (queryAnalyzerResponseDTO.getErrorList().size() == 0) {
if (log.isDebugEnabled()) {
log.debug("Maximum query depth of " + maxQueryDepth + " was not exceeded");
}
queryAnalyzerResponseDTO.setSuccess(true);
return queryAnalyzerResponseDTO;
}
log.error(queryAnalyzerResponseDTO.getErrorList().toString());
queryAnalyzerResponseDTO.setSuccess(false);
return queryAnalyzerResponseDTO;
}
}
queryAnalyzerResponseDTO.setSuccess(true);
return queryAnalyzerResponseDTO;
}
Aggregations