use of graphql.GraphQLError in project admin-console-beta by connexta.
the class GraphQLServlet method query.
private void query(String query, String operationName, Map<String, Object> variables, GraphQLSchema schema, HttpServletRequest req, HttpServletResponse resp, GraphQLContext context) throws IOException {
if (Subject.getSubject(AccessController.getContext()) == null && context.getSubject().isPresent()) {
Subject.doAs(context.getSubject().get(), new PrivilegedAction<Void>() {
@Override
@SneakyThrows
public Void run() {
query(query, operationName, variables, schema, req, resp, context);
return null;
}
});
} else {
runListeners(operationListeners, l -> runListener(l, it -> it.beforeGraphQLOperation(context, operationName, query, variables)));
ExecutionResult executionResult = new GraphQL(schema, getQueryExecutionStrategy(), getMutationExecutionStrategy()).execute(query, operationName, context, transformVariables(schema, query, variables));
List<GraphQLError> errors = executionResult.getErrors();
Object data = executionResult.getData();
String response = mapper.writeValueAsString(createResultFromDataAndErrors(data, errors));
resp.setContentType(APPLICATION_JSON_UTF8);
resp.setStatus(STATUS_OK);
resp.getWriter().write(response);
if (errorsPresent(errors)) {
runListeners(operationListeners, l -> l.onFailedGraphQLOperation(context, operationName, query, variables, data, errors));
} else {
runListeners(operationListeners, l -> l.onSuccessfulGraphQLOperation(context, operationName, query, variables, data));
}
}
}
Aggregations