use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GraphQLQueryComplexityInfoDTO in project carbon-apimgt by wso2.
the class GraphqlQueryAnalysisMappingUtil method fromDTOtoValidatedGraphqlComplexityInfo.
/**
* Converts a GraphQLQueryComplexityInfo DTO object into a GraphqlComplexityInfo object. During this process a
* basic validation is done comparing with the types of the schema
*
* @param graphQLQueryComplexityInfoDTO GraphQLQueryComplexityInfoDTO object
* @param schema GraphQL Schema
* @return a new GraphqlComplexityInfo object corresponding to given GraphQLQueryComplexityInfoDTO object
*/
public static GraphqlComplexityInfo fromDTOtoValidatedGraphqlComplexityInfo(GraphQLQueryComplexityInfoDTO graphQLQueryComplexityInfoDTO, String schema) {
SchemaParser schemaParser = new SchemaParser();
Set<String> complexityInfoTypeSet = schemaParser.parse(schema).types().keySet();
GraphqlComplexityInfo graphqlComplexityInfo = new GraphqlComplexityInfo();
List<CustomComplexityDetails> customComplexityDetailsList = new ArrayList<CustomComplexityDetails>();
for (GraphQLCustomComplexityInfoDTO graphQLCustomComplexityInfoDTO : graphQLQueryComplexityInfoDTO.getList()) {
String complexityType = graphQLCustomComplexityInfoDTO.getType();
if (complexityInfoTypeSet.contains(complexityType)) {
CustomComplexityDetails customComplexityDetails = new CustomComplexityDetails();
customComplexityDetails.setType(complexityType);
customComplexityDetails.setField(graphQLCustomComplexityInfoDTO.getField());
customComplexityDetails.setComplexityValue(graphQLCustomComplexityInfoDTO.getComplexityValue());
customComplexityDetailsList.add(customComplexityDetails);
} else {
log.error("Complexity Type : " + complexityType + " is not included in the original schema. Hence " + "skipped.");
}
}
graphqlComplexityInfo.setList(customComplexityDetailsList);
return graphqlComplexityInfo;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GraphQLQueryComplexityInfoDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdGraphqlPoliciesComplexityGet.
/**
* Get complexity details of a given API
*
* @param apiId apiId
* @param messageContext message context
* @return Response with complexity details of the GraphQL API
*/
@Override
public Response apisApiIdGraphqlPoliciesComplexityGet(String apiId, MessageContext messageContext) {
try {
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
API api = apiConsumer.getLightweightAPIByUUID(apiId, organization);
if (APIConstants.GRAPHQL_API.equals(api.getType())) {
GraphqlComplexityInfo graphqlComplexityInfo = apiConsumer.getComplexityDetails(apiId);
GraphQLQueryComplexityInfoDTO graphQLQueryComplexityInfoDTO = GraphqlQueryAnalysisMappingUtil.fromGraphqlComplexityInfotoDTO(graphqlComplexityInfo);
return Response.ok().entity(graphQLQueryComplexityInfoDTO).build();
} else {
throw new APIManagementException(ExceptionCodes.API_NOT_GRAPHQL);
}
} catch (APIManagementException e) {
// to expose the existence of the resource
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else if (isAuthorizationFailure(e)) {
RestApiUtil.handleAuthorizationFailure("Authorization failure while retrieving complexity details of API : " + apiId, e, log);
} else {
String msg = "Error while retrieving complexity details of API " + apiId;
RestApiUtil.handleInternalServerError(msg, e, log);
}
}
return null;
}
Aggregations