private Object coerceValueForScalar(GraphQLScalarType graphQLScalarType, Object value) { return graphQLScalarType.getCoercing().parseValue(value); }
private Object coerceValueForEnum(GraphQLEnumType graphQLEnumType, Object value) { return graphQLEnumType.getCoercing().parseValue(value); }
@Override public Object parseValue(Object input) { return getCoercingSuper().parseValue(input); }
private Object coerceValueForScalar(GraphQLScalarType graphQLScalarType, Object value) { return graphQLScalarType.getCoercing().parseValue(value); }
private Object coerceValueForEnum(GraphQLEnumType graphQLEnumType, Object value) { return graphQLEnumType.getCoercing().parseValue(value); }
@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); }
@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 void transformArgument(String[] argumentValues, GraphQLDirective.Builder directiveBuilder, List<GraphQLArgument> arguments, int i) { int finalI = i; GraphQLArgument graphQLArgument = arguments.get(i); directiveBuilder.argument(graphQLArgument.transform(builder -> { String argumentValue = argumentValues[finalI]; if (graphQLArgument.getType() instanceof GraphQLScalarType) { try { Object value = ((GraphQLScalarType) graphQLArgument.getType()).getCoercing().parseValue(argumentValue); builder.value(value); } catch (Exception e) { throw new GraphQLAnnotationsException("Could not parse argument value to argument type", e); } } else { throw new GraphQLAnnotationsException("Directive argument type must be a scalar!", null); } })); }