Search in sources :

Example 1 with QueryValidator

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;
}
Also used : GraphQLProcessorResponseDTO(org.wso2.carbon.apimgt.gateway.inbound.websocket.GraphQLProcessorResponseDTO) QueryValidator(org.wso2.carbon.apimgt.common.gateway.graphql.QueryValidator) QueryValidator(org.wso2.carbon.apimgt.common.gateway.graphql.QueryValidator) Validator(graphql.validation.Validator)

Aggregations

Validator (graphql.validation.Validator)1 QueryValidator (org.wso2.carbon.apimgt.common.gateway.graphql.QueryValidator)1 GraphQLProcessorResponseDTO (org.wso2.carbon.apimgt.gateway.inbound.websocket.GraphQLProcessorResponseDTO)1