private Object parseLiteral(Value value, GraphQLScalarType requiredType) { if (value instanceof NullValue) { return null; } return requiredType.getCoercing().parseLiteral(value); }
private Object coerceValueForScalar(GraphQLScalarType graphQLScalarType, Object value) { return graphQLScalarType.getCoercing().parseValue(value); }
protected Object serializeScalarValue(Object toAnalyze, GraphQLScalarType scalarType) throws CoercingSerializeException { return scalarType.getCoercing().serialize(toAnalyze); }
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 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); } }
public Builder(GraphQLScalarType existing) { name = existing.getName(); description = existing.getDescription(); coercing = existing.getCoercing(); definition = existing.getDefinition(); directives.putAll(getByName(existing.getDirectives(), GraphQLDirective::getName)); }
/** * 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 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, ((GraphQLScalarType) type).getCoercing()); if (!valid) { handleScalarError(value, (GraphQLScalarType) type);
@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); }
private Object parseLiteral(Value value, GraphQLScalarType requiredType) { if (value instanceof NullValue) { return null; } return requiredType.getCoercing().parseLiteral(value); }
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; }
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 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); } }
public Builder(GraphQLScalarType existing) { name = existing.getName(); description = existing.getDescription(); coercing = existing.getCoercing(); definition = existing.getDefinition(); directives.putAll(getByName(existing.getDirectives(), GraphQLDirective::getName)); }