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;
}
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);
}
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);
}
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);
}
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()));
}
Aggregations