Search in sources :

Example 1 with GraphQLCustomComplexityInfoDTO

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;
}
Also used : ArrayList(java.util.ArrayList) GraphQLCustomComplexityInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GraphQLCustomComplexityInfoDTO) CustomComplexityDetails(org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.CustomComplexityDetails) GraphQLQueryComplexityInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GraphQLQueryComplexityInfoDTO)

Example 2 with GraphQLCustomComplexityInfoDTO

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;
}
Also used : GraphqlComplexityInfo(org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.GraphqlComplexityInfo) ArrayList(java.util.ArrayList) GraphQLCustomComplexityInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GraphQLCustomComplexityInfoDTO) SchemaParser(graphql.schema.idl.SchemaParser) CustomComplexityDetails(org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.CustomComplexityDetails)

Aggregations

ArrayList (java.util.ArrayList)2 CustomComplexityDetails (org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.CustomComplexityDetails)2 GraphQLCustomComplexityInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GraphQLCustomComplexityInfoDTO)2 SchemaParser (graphql.schema.idl.SchemaParser)1 GraphqlComplexityInfo (org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.GraphqlComplexityInfo)1 GraphQLQueryComplexityInfoDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GraphQLQueryComplexityInfoDTO)1