Search in sources :

Example 1 with SourceLocation

use of graphql.language.SourceLocation in project graphql-java by graphql-java.

the class GraphqlAntlrToLanguage method getCommentOnChannel.

private List<Comment> getCommentOnChannel(List<Token> refChannel) {
    List<Comment> comments = new ArrayList<>();
    for (Token refTok : refChannel) {
        String text = refTok.getText();
        // consumers can decide that
        if (text == null) {
            continue;
        }
        text = text.replaceFirst("^#", "");
        comments.add(new Comment(text, new SourceLocation(refTok.getLine(), refTok.getCharPositionInLine())));
    }
    return comments;
}
Also used : SourceLocation(graphql.language.SourceLocation) Comment(graphql.language.Comment) ArrayList(java.util.ArrayList) Token(org.antlr.v4.runtime.Token) StringValueParsing.parseTripleQuotedString(graphql.parser.StringValueParsing.parseTripleQuotedString) StringValueParsing.parseSingleQuotedString(graphql.parser.StringValueParsing.parseSingleQuotedString)

Example 2 with SourceLocation

use of graphql.language.SourceLocation in project graphql-java by graphql-java.

the class GraphqlAntlrToLanguage method newDescription.

private Description newDescription(GraphqlParser.DescriptionContext descriptionCtx) {
    if (descriptionCtx == null) {
        return null;
    }
    GraphqlParser.StringValueContext stringValueCtx = descriptionCtx.stringValue();
    if (stringValueCtx == null) {
        return null;
    }
    boolean multiLine = stringValueCtx.TripleQuotedStringValue() != null;
    String content = stringValueCtx.getText();
    if (multiLine) {
        content = parseTripleQuotedString(content);
    } else {
        content = parseSingleQuotedString(content);
    }
    SourceLocation sourceLocation = getSourceLocation(descriptionCtx);
    return new Description(content, sourceLocation, multiLine);
}
Also used : SourceLocation(graphql.language.SourceLocation) Description(graphql.language.Description) GraphqlParser(graphql.parser.antlr.GraphqlParser) StringValueParsing.parseTripleQuotedString(graphql.parser.StringValueParsing.parseTripleQuotedString) StringValueParsing.parseSingleQuotedString(graphql.parser.StringValueParsing.parseSingleQuotedString)

Example 3 with SourceLocation

use of graphql.language.SourceLocation in project graphql-java by graphql-java.

the class InvalidSyntaxError method toInvalidSyntaxError.

/**
 * Creates an invalid syntax error object from an exception
 *
 * @param parseException the parse exception
 *
 * @return a new invalid syntax error object
 */
public static InvalidSyntaxError toInvalidSyntaxError(Exception parseException) {
    String msg = parseException.getMessage();
    SourceLocation sourceLocation = null;
    if (parseException.getCause() instanceof RecognitionException) {
        RecognitionException recognitionException = (RecognitionException) parseException.getCause();
        msg = recognitionException.getMessage();
        sourceLocation = new SourceLocation(recognitionException.getOffendingToken().getLine(), recognitionException.getOffendingToken().getCharPositionInLine());
    }
    return new InvalidSyntaxError(sourceLocation, msg);
}
Also used : SourceLocation(graphql.language.SourceLocation) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 4 with SourceLocation

use of graphql.language.SourceLocation in project graphql-java by graphql-java.

the class SimpleDataFetcherExceptionHandler method accept.

@Override
public void accept(DataFetcherExceptionHandlerParameters handlerParameters) {
    Throwable exception = handlerParameters.getException();
    SourceLocation sourceLocation = handlerParameters.getField().getSourceLocation();
    ExecutionPath path = handlerParameters.getPath();
    ExceptionWhileDataFetching error = new ExceptionWhileDataFetching(path, exception, sourceLocation);
    handlerParameters.getExecutionContext().addError(error);
    log.warn(error.getMessage(), exception);
}
Also used : SourceLocation(graphql.language.SourceLocation) ExceptionWhileDataFetching(graphql.ExceptionWhileDataFetching)

Example 5 with SourceLocation

use of graphql.language.SourceLocation in project graphql-java by graphql-java.

the class AbstractRule method addError.

public void addError(ValidationErrorType validationErrorType, List<? extends Node> locations, String description) {
    List<SourceLocation> locationList = new ArrayList<>();
    for (Node node : locations) {
        locationList.add(node.getSourceLocation());
    }
    validationErrorCollector.addError(new ValidationError(validationErrorType, locationList, description, getQueryPath()));
}
Also used : SourceLocation(graphql.language.SourceLocation) Node(graphql.language.Node) ArrayList(java.util.ArrayList)

Aggregations

SourceLocation (graphql.language.SourceLocation)5 StringValueParsing.parseSingleQuotedString (graphql.parser.StringValueParsing.parseSingleQuotedString)2 StringValueParsing.parseTripleQuotedString (graphql.parser.StringValueParsing.parseTripleQuotedString)2 ArrayList (java.util.ArrayList)2 ExceptionWhileDataFetching (graphql.ExceptionWhileDataFetching)1 Comment (graphql.language.Comment)1 Description (graphql.language.Description)1 Node (graphql.language.Node)1 GraphqlParser (graphql.parser.antlr.GraphqlParser)1 RecognitionException (org.antlr.v4.runtime.RecognitionException)1 Token (org.antlr.v4.runtime.Token)1