private Object coerceValueForEnum(GraphQLEnumType graphQLEnumType, Object value) { return graphQLEnumType.getCoercing().parseValue(value); }
private Object coerce(GraphQLType type, Object value) { if (value == null) { return null; } if (type instanceof GraphQLEnumType) { return ((GraphQLEnumType) type).getCoercing().serialize(value); } else { return ((GraphQLScalarType) type).getCoercing().serialize(value); } }
private static Object serialize(GraphQLType type, Object value) { if (type instanceof GraphQLScalarType) { return ((GraphQLScalarType) type).getCoercing().serialize(value); } else { return ((GraphQLEnumType) type).getCoercing().serialize(value); } }
/** * 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 Object coerceValueAst(GraphqlFieldVisibility fieldVisibility, GraphQLType type, Value inputValue, Map<String, Object> variables) { if (inputValue instanceof VariableReference) { return variables.get(((VariableReference) inputValue).getName()); } if (inputValue instanceof NullValue) { return null; } if (type instanceof GraphQLScalarType) { return parseLiteral(inputValue, ((GraphQLScalarType) type).getCoercing(), variables); } if (isNonNull(type)) { return coerceValueAst(fieldVisibility, unwrapOne(type), inputValue, variables); } if (type instanceof GraphQLInputObjectType) { return coerceValueAstForInputObject(fieldVisibility, (GraphQLInputObjectType) type, (ObjectValue) inputValue, variables); } if (type instanceof GraphQLEnumType) { return parseLiteral(inputValue, ((GraphQLEnumType) type).getCoercing(), variables); } if (isList(type)) { return coerceValueAstForList(fieldVisibility, (GraphQLList) type, inputValue, variables); } return null; }
boolean valid = parseLiteral(value, ((GraphQLEnumType) type).getCoercing()); if (!valid) { handleEnumError(value, (GraphQLEnumType) type);
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(); }
public Coercing getCoercingSuper() { return super.getCoercing(); }
private Object coerceValueForEnum(GraphQLEnumType graphQLEnumType, Object value) { return graphQLEnumType.getCoercing().parseValue(value); }
@Override protected ExecutionResult completeValueForEnum(GraphQLEnumType enumType, Object result) { return new GraphQLRxExecutionResult(Observable.just(enumType.getCoercing().serialize(result)), Observable.just(null), Observable.just(0.0)); }
private static Object serialize(GraphQLType type, Object value) { if (type instanceof GraphQLScalarType) { return ((GraphQLScalarType) type).getCoercing().serialize(value); } else { return ((GraphQLEnumType) type).getCoercing().serialize(value); } }
private Object coerce(GraphQLType type, Object value) { if (value == null) { return null; } if (type instanceof GraphQLEnumType) { return ((GraphQLEnumType) type).getCoercing().serialize(value); } else { return ((GraphQLScalarType) type).getCoercing().serialize(value); } }
@Override protected ExecutionResult completeValue(ExecutionContext executionContext, ExecutionParameters parameters, List<Field> fields) { GraphQLType fieldType = parameters.typeInfo().type(); Object result = parameters.source(); if (result instanceof Enum && fieldType instanceof GraphQLEnumType) { Object value = ((GraphQLEnumType) fieldType).getCoercing().parseValue(((Enum) result).name()); return super.completeValue(executionContext, withSource(parameters, value), fields); } if (result instanceof Optional) { Object value = ((Optional<?>) result).orElse(null); return completeValue(executionContext, withSource(parameters, value), fields); } return super.completeValue(executionContext, parameters, fields); }
@Override protected FieldValueInfo completeValue(ExecutionContext executionContext, ExecutionStrategyParameters parameters) throws NonNullableFieldWasNullException { graphql.schema.GraphQLType fieldType = parameters.getExecutionStepInfo().getType(); Object result = parameters.getSource(); if (result instanceof Enum && fieldType instanceof GraphQLEnumType) { Object value = ((GraphQLEnumType) fieldType).getCoercing().parseValue(((Enum) result).name()); return super.completeValue(executionContext, withSource(parameters, value)); } if (result instanceof Optional) { Object value = ((Optional<?>) result).orElse(null); return completeValue(executionContext, withSource(parameters, value)); } return super.completeValue(executionContext, parameters); }
/** * 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 Object coerceValueAst(GraphqlFieldVisibility fieldVisibility, GraphQLType type, Value inputValue, Map<String, Object> variables) { if (inputValue instanceof VariableReference) { return variables.get(((VariableReference) inputValue).getName()); } if (inputValue instanceof NullValue) { return null; } if (type instanceof GraphQLScalarType) { return parseLiteral(inputValue, ((GraphQLScalarType) type).getCoercing(), variables); } if (isNonNull(type)) { return coerceValueAst(fieldVisibility, unwrapOne(type), inputValue, variables); } if (type instanceof GraphQLInputObjectType) { return coerceValueAstForInputObject(fieldVisibility, (GraphQLInputObjectType) type, (ObjectValue) inputValue, variables); } if (type instanceof GraphQLEnumType) { return parseLiteral(inputValue, ((GraphQLEnumType) type).getCoercing(), variables); } if (isList(type)) { return coerceValueAstForList(fieldVisibility, (GraphQLList) type, inputValue, variables); } return null; }
boolean valid = parseLiteral(value, ((GraphQLEnumType) type).getCoercing()); if (!valid) { handleEnumError(value, (GraphQLEnumType) type);
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(); }