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

graphql.scalars.numeric.IntCoercing Maven / Gradle / Ivy

There is a newer version: 2023-01-24T02-11-56-babda5f
Show newest version
package graphql.scalars.numeric;

import graphql.Internal;
import graphql.language.Value;
import graphql.schema.Coercing;
import graphql.schema.CoercingParseLiteralException;
import graphql.schema.CoercingParseValueException;
import graphql.schema.CoercingSerializeException;

import java.util.function.Function;

import static graphql.Scalars.GraphQLInt;

@Internal
abstract class IntCoercing implements Coercing {

    protected abstract Integer check(Integer i, Function exceptionMaker);

    @Override
    public Integer serialize(Object input) throws CoercingSerializeException {
        Integer i = (Integer) GraphQLInt.getCoercing().serialize(input);
        return check(i, CoercingSerializeException::new);
    }

    @Override
    public Integer parseValue(Object input) throws CoercingParseValueException {
        Integer i = (Integer) GraphQLInt.getCoercing().parseValue(input);
        return check(i, CoercingParseValueException::new);
    }

    @Override
    public Integer parseLiteral(Object input) throws CoercingParseLiteralException {
        Integer i = (Integer) GraphQLInt.getCoercing().parseLiteral(input);
        return check(i, CoercingParseLiteralException::new);
    }

    @Override
    public Value valueToLiteral(Object input) {
        return GraphQLInt.getCoercing().valueToLiteral(input);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy