graphql.parser.Parser Java Examples

The following examples show how to use graphql.parser.Parser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryValidator.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
public QueryValidator(GraphQLSchema schema) {

        this.schema = schema;
        this.validationErrors = new ArrayList<>();
        this.validator = new Validator();
        this.parser = new Parser();

    }
 
Example #2
Source File: QueryValidator.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
public QueryValidator(GraphQLSchema schema) {

        this.schema = schema;
        this.validationErrors = new ArrayList<>();
        this.validator = new Validator();
        this.parser = new Parser();

    }
 
Example #3
Source File: QueryComplexityCalculator.java    From glitr with MIT License 5 votes vote down vote up
public QueryComplexityCalculator() {
    this.maxCharacterLimit = 10000;
    this.maxDepthLimit = 8;
    this.maxScoreLimit = 500;
    this.defaultMultiplier = 10d;
    this.documentParser = new Parser();
}
 
Example #4
Source File: QueryComplexityCalculator.java    From glitr with MIT License 5 votes vote down vote up
public QueryComplexityCalculator(int maxCharacterLimit, int maxDepthLimit, int maxScoreLimit, int defaultMultiplier) {
    this.maxCharacterLimit = maxCharacterLimit;
    this.maxDepthLimit = maxDepthLimit;
    this.maxScoreLimit = maxScoreLimit;
    this.defaultMultiplier = defaultMultiplier;
    this.documentParser = new Parser();
}
 
Example #5
Source File: QueryComplexityCalculator.java    From glitr with MIT License 5 votes vote down vote up
public QueryComplexityCalculator(int maxCharacterLimit, int maxDepthLimit, int maxScoreLimit, int defaultMultiplier, Parser documentParser) {
    this.maxCharacterLimit = maxCharacterLimit;
    this.maxDepthLimit = maxDepthLimit;
    this.maxScoreLimit = maxScoreLimit;
    this.defaultMultiplier = defaultMultiplier;
    this.documentParser = documentParser;
}
 
Example #6
Source File: GqlModel.java    From manifold with Apache License 2.0 4 votes vote down vote up
private void parse( Reader schemaInput ) throws ParseCancellationException
{
  Parser parser = new Parser();
  Document document = parser.parseDocument( schemaInput );
  buildRegistry( document );
}
 
Example #7
Source File: GraphQLAPIHandler.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
public boolean handleRequest(MessageContext messageContext) {
    try {
        String payload;
        Parser parser = new Parser();

        org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext).
                getAxis2MessageContext();
        String requestPath = messageContext.getProperty(REST_SUB_REQUEST_PATH).toString();
        if (requestPath != null && !requestPath.isEmpty()) {
            String[] queryParams = ((Axis2MessageContext) messageContext).getProperties().
                    get(REST_SUB_REQUEST_PATH).toString().split(QUERY_PATH_STRING);
            if (queryParams.length > 1) {
                payload = URLDecoder.decode(queryParams[1], UNICODE_TRANSFORMATION_FORMAT);
            } else {
                RelayUtils.buildMessage(axis2MC);
                OMElement body = axis2MC.getEnvelope().getBody().getFirstElement();
                if (body != null && body.getFirstElement() != null) {
                    payload = body.getFirstElement().getText();
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug("Invalid query parameter " + queryParams[0]);
                    }
                    handleFailure(messageContext, "Invalid query parameter");
                    return false;
                }
            }
            messageContext.setProperty(APIConstants.GRAPHQL_PAYLOAD, payload);
        } else {
            handleFailure(messageContext, "Request path cannot be empty");
            return false;
        }

        // Validate payload with graphQLSchema
        Document document = parser.parseDocument(payload);

        if (validatePayloadWithSchema(messageContext, document)) {
            supportForBasicAndAuthentication(messageContext);

            // Extract the operation type and operations from the payload
            for (Definition definition : document.getDefinitions()) {
                if (definition instanceof OperationDefinition) {
                    OperationDefinition operation = (OperationDefinition) definition;
                    if (operation.getOperation() != null) {
                        String httpVerb = ((Axis2MessageContext) messageContext).getAxis2MessageContext().
                                getProperty(HTTP_METHOD).toString();
                        messageContext.setProperty(HTTP_VERB, httpVerb);
                        ((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty(HTTP_METHOD,
                                operation.getOperation().toString());
                        String operationList = getOperationList(messageContext, operation);
                        messageContext.setProperty(APIConstants.API_ELECTED_RESOURCE, operationList);
                        if (log.isDebugEnabled()) {
                            log.debug("Operation list has been successfully added to elected property");
                        }
                        return true;
                    }
                } else {
                    handleFailure(messageContext, "Operation definition cannot be empty");
                    return false;
                }
            }
        } else {
            return false;
        }
    } catch (IOException | XMLStreamException | InvalidSyntaxException e) {
        log.error(e.getMessage());
        handleFailure(messageContext, e.getMessage());
    }
    return false;
}