use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GraphQLCustomComplexityInfoDTO in project carbon-apimgt by wso2.
the class GraphqlQueryAnalysisMappingUtil method fromGraphqlComplexityInfotoDTO.
/**
* Converts a GraphqlComplexityInfo object into a DTO object.
*
* @param graphqlComplexityInfo GraphqlComplexityInfo object
* @return a new GraphQLQueryComplexityInfoDTO object corresponding to given GraphqlComplexityInfo object
*/
public static GraphQLQueryComplexityInfoDTO fromGraphqlComplexityInfotoDTO(GraphqlComplexityInfo graphqlComplexityInfo) {
GraphQLQueryComplexityInfoDTO graphQLQueryComplexityInfoDTO = new GraphQLQueryComplexityInfoDTO();
List<GraphQLCustomComplexityInfoDTO> graphQLCustomComplexityInfoDTOList = new ArrayList<GraphQLCustomComplexityInfoDTO>();
for (CustomComplexityDetails customComplexityDetails : graphqlComplexityInfo.getList()) {
GraphQLCustomComplexityInfoDTO graphQLCustomComplexityInfoDTO = new GraphQLCustomComplexityInfoDTO();
graphQLCustomComplexityInfoDTO.setType(customComplexityDetails.getType());
graphQLCustomComplexityInfoDTO.setField(customComplexityDetails.getField());
graphQLCustomComplexityInfoDTO.setComplexityValue(customComplexityDetails.getComplexityValue());
graphQLCustomComplexityInfoDTOList.add(graphQLCustomComplexityInfoDTO);
}
graphQLQueryComplexityInfoDTO.setList(graphQLCustomComplexityInfoDTOList);
return graphQLQueryComplexityInfoDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GraphQLCustomComplexityInfoDTO 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;
}
Aggregations