Search in sources :

Example 1 with CoercingSerializeException

use of graphql.schema.CoercingSerializeException in project graphql-java by graphql-java.

the class ExecutionResultJSONTesting method createER.

private ExecutionResult createER() {
    List<GraphQLError> errors = new ArrayList<>();
    errors.add(new ValidationError(ValidationErrorType.UnknownType, mkLocations(), "Test ValidationError"));
    errors.add(new MissingRootTypeException("Mutations are not supported.", null));
    errors.add(new InvalidSyntaxError(mkLocations(), "Not good syntax m'kay"));
    errors.add(new NonNullableFieldWasNullError(new NonNullableFieldWasNullException(mkTypeInfo(), mkPath())));
    errors.add(new SerializationError(mkPath(), new CoercingSerializeException("Bad coercing")));
    errors.add(new ExceptionWhileDataFetching(mkPath(), new RuntimeException("Bang"), mkLocation(666, 999)));
    return new ExecutionResultImpl(null, errors);
}
Also used : NonNullableFieldWasNullException(graphql.execution.NonNullableFieldWasNullException) MissingRootTypeException(graphql.execution.MissingRootTypeException) NonNullableFieldWasNullError(graphql.execution.NonNullableFieldWasNullError) ArrayList(java.util.ArrayList) SerializationError(graphql.SerializationError) InvalidSyntaxError(graphql.InvalidSyntaxError) ExecutionResultImpl(graphql.ExecutionResultImpl) GraphQLError(graphql.GraphQLError) ExceptionWhileDataFetching(graphql.ExceptionWhileDataFetching) ValidationError(graphql.validation.ValidationError) CoercingSerializeException(graphql.schema.CoercingSerializeException)

Example 2 with CoercingSerializeException

use of graphql.schema.CoercingSerializeException in project graphql-java by graphql-java.

the class ExecutionStrategy method completeValueForEnum.

/**
 * Called to turn an object into a enum value according to the {@link GraphQLEnumType} by asking that enum type to coerce the object into a valid value
 *
 * @param executionContext contains the top level execution parameters
 * @param parameters       contains the parameters holding the fields to be executed and source object
 * @param enumType         the type of the enum
 * @param result           the result to be coerced
 *
 * @return an {@link ExecutionResult}
 */
protected CompletableFuture<ExecutionResult> completeValueForEnum(ExecutionContext executionContext, ExecutionStrategyParameters parameters, GraphQLEnumType enumType, Object result) {
    Object serialized;
    try {
        serialized = enumType.getCoercing().serialize(result);
    } catch (CoercingSerializeException e) {
        serialized = handleCoercionProblem(executionContext, parameters, e);
    }
    serialized = parameters.getNonNullFieldValidator().validate(parameters.getPath(), serialized);
    return completedFuture(new ExecutionResultImpl(serialized, null));
}
Also used : ExecutionResultImpl(graphql.ExecutionResultImpl) CoercingSerializeException(graphql.schema.CoercingSerializeException)

Example 3 with CoercingSerializeException

use of graphql.schema.CoercingSerializeException in project graphql-java by graphql-java.

the class ExecutionStrategy method completeValueForScalar.

/**
 * Called to turn an object into a scalar value according to the {@link GraphQLScalarType} by asking that scalar type to coerce the object
 * into a valid value
 *
 * @param executionContext contains the top level execution parameters
 * @param parameters       contains the parameters holding the fields to be executed and source object
 * @param scalarType       the type of the scalar
 * @param result           the result to be coerced
 *
 * @return an {@link ExecutionResult}
 */
protected CompletableFuture<ExecutionResult> completeValueForScalar(ExecutionContext executionContext, ExecutionStrategyParameters parameters, GraphQLScalarType scalarType, Object result) {
    Object serialized;
    try {
        serialized = scalarType.getCoercing().serialize(result);
    } catch (CoercingSerializeException e) {
        serialized = handleCoercionProblem(executionContext, parameters, e);
    }
    // 6.6.1 http://facebook.github.io/graphql/#sec-Field-entries
    if (serialized instanceof Double && ((Double) serialized).isNaN()) {
        serialized = null;
    }
    serialized = parameters.getNonNullFieldValidator().validate(parameters.getPath(), serialized);
    return completedFuture(new ExecutionResultImpl(serialized, null));
}
Also used : ExecutionResultImpl(graphql.ExecutionResultImpl) CoercingSerializeException(graphql.schema.CoercingSerializeException) OptionalDouble(java.util.OptionalDouble)

Aggregations

ExecutionResultImpl (graphql.ExecutionResultImpl)3 CoercingSerializeException (graphql.schema.CoercingSerializeException)3 ExceptionWhileDataFetching (graphql.ExceptionWhileDataFetching)1 GraphQLError (graphql.GraphQLError)1 InvalidSyntaxError (graphql.InvalidSyntaxError)1 SerializationError (graphql.SerializationError)1 MissingRootTypeException (graphql.execution.MissingRootTypeException)1 NonNullableFieldWasNullError (graphql.execution.NonNullableFieldWasNullError)1 NonNullableFieldWasNullException (graphql.execution.NonNullableFieldWasNullException)1 ValidationError (graphql.validation.ValidationError)1 ArrayList (java.util.ArrayList)1 OptionalDouble (java.util.OptionalDouble)1