protected Object serializeScalarValue(Object toAnalyze, GraphQLScalarType scalarType) throws CoercingSerializeException { return scalarType.getCoercing().serialize(toAnalyze); }
/** * 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 a promise to 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); } // TODO: fix that: this should not be handled here //6.6.1 http://facebook.github.io/graphql/#sec-Field-entries if (serialized instanceof Double && ((Double) serialized).isNaN()) { serialized = null; } try { serialized = parameters.getNonNullFieldValidator().validate(parameters.getPath(), serialized); } catch (NonNullableFieldWasNullException e) { return exceptionallyCompletedFuture(e); } return completedFuture(new ExecutionResultImpl(serialized, null)); }
/** * 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 a promise to 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); } try { serialized = parameters.getNonNullFieldValidator().validate(parameters.getPath(), serialized); } catch (NonNullableFieldWasNullException e) { return exceptionallyCompletedFuture(e); } return completedFuture(new ExecutionResultImpl(serialized, null)); }
private FetchedValueAnalysis analyzeEnumValue(FetchedValue fetchedValue, Object toAnalyze, GraphQLEnumType enumType, ExecutionStepInfo executionInfo) { if (toAnalyze == null) { return newFetchedValueAnalysis(SCALAR) .fetchedValue(fetchedValue) .executionStepInfo(executionInfo) .nullValue() .build(); } Object serialized; try { serialized = enumType.getCoercing().serialize(toAnalyze); } catch (CoercingSerializeException e) { SerializationError error = new SerializationError(executionInfo.getPath(), e); return newFetchedValueAnalysis(SCALAR) .fetchedValue(fetchedValue) .executionStepInfo(executionInfo) .nullValue() .error(error) .build(); } // handle non null values return newFetchedValueAnalysis(ENUM) .fetchedValue(fetchedValue) .executionStepInfo(executionInfo) .completedValue(serialized) .build(); }
@Override public Object serialize(Object dataFetcherResult) { if (dataFetcherResult instanceof JsonPrimitive) { return JsonPrimitiveNode.getCoercing().serialize(dataFetcherResult); } return dataFetcherResult; }
protected Object serializeScalarValue(Object toAnalyze, GraphQLScalarType scalarType) throws CoercingSerializeException { return scalarType.getCoercing().serialize(toAnalyze); }
@Override protected ExecutionResult completeValueForEnum(GraphQLEnumType enumType, Object result) { return new GraphQLRxExecutionResult(Observable.just(enumType.getCoercing().serialize(result)), Observable.just(null), Observable.just(0.0)); }
@Override protected ExecutionResult completeValueForScalar(GraphQLScalarType scalarType, Object result) { return new GraphQLRxExecutionResult(Observable.just(scalarType.getCoercing().serialize(result)), Observable.just(null), Observable.just(0.0)); }
private static String dateToString(Date date) { if (Date.class.equals(date.getClass())) { return date.toInstant().toString(); } else if (isScalar(date.getClass())) { return Scalars.toGraphQLScalarType(date.getClass()).getCoercing().serialize(date).toString(); } else { throw serializationException(date, Date.class, java.sql.Date.class, Time.class, Timestamp.class); } }
@Override public Object serialize(Object dataFetcherResult) { GraphQLScalarType scalar = toGraphQLScalarType(dataFetcherResult.getClass()); return scalar != null ? scalar.getCoercing().serialize(dataFetcherResult) : dataFetcherResult; }
@Override public Object serialize(Object dataFetcherResult) { GraphQLScalarType scalar = JacksonScalars.toGraphQLScalarType(dataFetcherResult.getClass()); return scalar != null ? scalar.getCoercing().serialize(dataFetcherResult) : dataFetcherResult; }
/** * 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 a promise to 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); } // TODO: fix that: this should not be handled here //6.6.1 http://facebook.github.io/graphql/#sec-Field-entries if (serialized instanceof Double && ((Double) serialized).isNaN()) { serialized = null; } try { serialized = parameters.getNonNullFieldValidator().validate(parameters.getPath(), serialized); } catch (NonNullableFieldWasNullException e) { return exceptionallyCompletedFuture(e); } return completedFuture(new ExecutionResultImpl(serialized, null)); }
/** * 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 a promise to 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); } try { serialized = parameters.getNonNullFieldValidator().validate(parameters.getPath(), serialized); } catch (NonNullableFieldWasNullException e) { return exceptionallyCompletedFuture(e); } return completedFuture(new ExecutionResultImpl(serialized, null)); }
private FetchedValueAnalysis analyzeEnumValue(FetchedValue fetchedValue, Object toAnalyze, GraphQLEnumType enumType, ExecutionStepInfo executionInfo) { if (toAnalyze == null) { return newFetchedValueAnalysis(SCALAR) .fetchedValue(fetchedValue) .executionStepInfo(executionInfo) .nullValue() .build(); } Object serialized; try { serialized = enumType.getCoercing().serialize(toAnalyze); } catch (CoercingSerializeException e) { SerializationError error = new SerializationError(executionInfo.getPath(), e); return newFetchedValueAnalysis(SCALAR) .fetchedValue(fetchedValue) .executionStepInfo(executionInfo) .nullValue() .error(error) .build(); } // handle non null values return newFetchedValueAnalysis(ENUM) .fetchedValue(fetchedValue) .executionStepInfo(executionInfo) .completedValue(serialized) .build(); }