use of org.wso2.carbon.apimgt.common.gateway.graphql.QueryValidator in project carbon-apimgt by wso2.
the class GraphQLRequestProcessor method validateQueryPayload.
/**
* Validates GraphQL query payload using QueryValidator and graphql schema of the invoking API.
*
* @param inboundMessageContext InboundMessageContext
* @param document Graphql payload
* @param operationId Graphql message id
* @return InboundProcessorResponseDTO
*/
private InboundProcessorResponseDTO validateQueryPayload(InboundMessageContext inboundMessageContext, Document document, String operationId) {
GraphQLProcessorResponseDTO responseDTO = new GraphQLProcessorResponseDTO();
responseDTO.setId(operationId);
QueryValidator queryValidator = new QueryValidator(new Validator());
// payload validation
String validationErrorMessage = queryValidator.validatePayload(inboundMessageContext.getGraphQLSchemaDTO().getGraphQLSchema(), document);
if (validationErrorMessage != null) {
String error = WebSocketApiConstants.FrameErrorConstants.GRAPHQL_INVALID_QUERY_MESSAGE + " : " + validationErrorMessage;
log.error(error);
responseDTO.setError(true);
responseDTO.setErrorCode(WebSocketApiConstants.FrameErrorConstants.GRAPHQL_INVALID_QUERY);
responseDTO.setErrorMessage(error);
return responseDTO;
}
return responseDTO;
}
Aggregations