private Object coerceValueForScalar(GraphQLScalarType graphQLScalarType, Object value) { return graphQLScalarType.getCoercing().parseValue(value); }
private boolean parseLiteral(Value value, Coercing coercing) { try { return coercing.parseLiteral(value) != null; } catch (CoercingParseLiteralException e) { return false; } }
private Object coerceValueForEnum(GraphQLEnumType graphQLEnumType, Object value) { return graphQLEnumType.getCoercing().parseValue(value); }
private Object parseLiteral(Value inputValue, Coercing coercing, Map<String, Object> variables) { // the CoercingParseLiteralException exception that could happen here has been validated earlier via ValidationUtil return coercing.parseLiteral(inputValue, variables); }
protected Object serializeScalarValue(Object toAnalyze, GraphQLScalarType scalarType) throws CoercingSerializeException { return scalarType.getCoercing().serialize(toAnalyze); }
@Override public Object parseValue(Object input) { return getCoercingSuper().parseValue(input); }
/** * Called during query execution to convert an query input AST node into a Java object acceptable for the scalar type. The input * object will be an instance of {@link graphql.language.Value}. * * Note : You should not allow {@link java.lang.RuntimeException}s to come out of your parseLiteral method, but rather * catch them and fire them as {@link graphql.schema.CoercingParseLiteralException} instead as per the method contract. * * Many scalar types don't need to implement this method because they do'nt take AST {@link graphql.language.VariableReference} * objects and convert them into actual values. But for those scalar types that want to do this, then this * method should be implemented. * * @param input is never null * @param variables the resolved variables passed to the query * * @return a parsed value which is never null * * @throws graphql.schema.CoercingParseLiteralException if input literal can't be parsed */ @SuppressWarnings("unused") default I parseLiteral(Object input, Map<String, Object> variables) throws CoercingParseLiteralException { return parseLiteral(input); }
/** * 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)); }
private Object coerceValueForScalar(GraphQLScalarType graphQLScalarType, Object value) { return graphQLScalarType.getCoercing().parseValue(value); }
private Object parseLiteral(Value value, GraphQLScalarType requiredType) { if (value instanceof NullValue) { return null; } return requiredType.getCoercing().parseLiteral(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 coerceValueForEnum(GraphQLEnumType graphQLEnumType, Object value) { return graphQLEnumType.getCoercing().parseValue(value); }
private boolean isArgumentValueScalarLiteral(GraphQLScalarType scalarType, Value instanceValue) { try { scalarType.getCoercing().parseLiteral(instanceValue); return true; } catch (CoercingParseLiteralException ex) { log.debug("Attempted parsing literal into '{}' but got the following error: ", scalarType.getName(), ex); return false; } } }
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 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); }
private boolean parseLiteral(Value value, Coercing coercing) { try { return coercing.parseLiteral(value) != null; } catch (CoercingParseLiteralException e) { return false; } }
@Override public Object serialize(Object dataFetcherResult) { if (dataFetcherResult instanceof JsonPrimitive) { return JsonPrimitiveNode.getCoercing().serialize(dataFetcherResult); } return dataFetcherResult; }
@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); }