All Downloads are FREE. Search and download functionalities are using the official Maven repository.

graphql.schema.idl.errors.BaseError Maven / Gradle / Ivy

The newest version!
package graphql.schema.idl.errors;

import graphql.ErrorType;
import graphql.GraphQLError;
import graphql.GraphQLException;
import graphql.language.Node;
import graphql.language.SourceLocation;

import java.util.Collections;
import java.util.List;

class BaseError extends GraphQLException implements GraphQLError {
    protected static final SourceLocation NO_WHERE = new SourceLocation(-1, -1);

    private Node node;

    public BaseError(Node node, String msg) {
        super(msg);
        this.node = node;
    }

    public static String lineCol(Node node) {
        SourceLocation sourceLocation = node.getSourceLocation() == null ? NO_WHERE : node.getSourceLocation();
        return String.format("[@%d:%d]", sourceLocation.getLine(), sourceLocation.getColumn());
    }

    @Override
    public List getLocations() {
        return node == null ? Collections.singletonList(NO_WHERE) : Collections.singletonList(node.getSourceLocation());
    }

    @Override
    public ErrorType getErrorType() {
        return ErrorType.ValidationError;
    }

    @Override
    public String toString() {
        return "BaseError{" +
                "msg='" + getMessage() + '\'' +
                ", node=" + node +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy