@SuppressWarnings("unchecked") @Override public void writeCustom(@NotNull ResponseField.CustomTypeField field, @Nullable Object value) { CustomTypeAdapter typeAdapter = scalarTypeAdapters.adapterFor(field.scalarType()); writeScalarFieldValue(field, value != null ? typeAdapter.encode(value).value : null); }
recordSet.put(stringField.responseName(), "string"); recordSet.put(booleanField.responseName(), true); recordSet.put(integerField.responseName(), BigDecimal.valueOf(1)); recordSet.put(longField.responseName(), BigDecimal.valueOf(2)); recordSet.put(floatField.responseName(), BigDecimal.valueOf(3.99)); recordSet.put(doubleField.responseName(), BigDecimal.valueOf(4.99)); recordSet.put(unsupportedField.responseName(), "smth");
@SuppressWarnings("unchecked") @Override public <T> T readCustomType(ResponseField.CustomTypeField field) { if (shouldSkip(field)) { return null; } willResolve(field); Object value = fieldValueResolver.valueFor(recordSet, field); checkValue(field, value); final T result; if (value == null) { readerShadow.didResolveNull(); result = null; } else { CustomTypeAdapter<T> typeAdapter = scalarTypeAdapters.adapterFor(field.scalarType()); readerShadow.didResolveScalar(value); result = typeAdapter.decode(value.toString()); } didResolve(field); return result; }
@SuppressWarnings("unchecked") @Override public <T> T readCustomType(ResponseField.CustomTypeField field) { if (shouldSkip(field)) { return null; } willResolve(field); Object value = fieldValueResolver.valueFor(recordSet, field); checkValue(field, value); final T result; if (value == null) { readerShadow.didResolveNull(); result = null; } else { CustomTypeAdapter<T> typeAdapter = scalarTypeAdapters.adapterFor(field.scalarType()); readerShadow.didResolveScalar(value); result = typeAdapter.decode(value.toString()); } didResolve(field); return result; }
/** * Factory method for creating a Field instance representing a custom GraphQL Scalar type, {@link Type#CUSTOM} * * @param responseName alias for the result of a field * @param fieldName name of the field in the GraphQL operation * @param arguments arguments to be passed along with the field * @param optional whether the arguments passed along are optional or required * @param scalarType the custom scalar type of the field * @param conditions list of conditions for this field * @return Field instance representing {@link Type#CUSTOM} */ public static CustomTypeField forCustomType(String responseName, String fieldName, Map<String, Object> arguments, boolean optional, ScalarType scalarType, List<Condition> conditions) { return new CustomTypeField(responseName, fieldName, arguments, optional, scalarType, conditions); }
/** * Factory method for creating a Field instance representing a custom GraphQL Scalar type, {@link Type#CUSTOM} * * @param responseName alias for the result of a field * @param fieldName name of the field in the GraphQL operation * @param arguments arguments to be passed along with the field * @param optional whether the arguments passed along are optional or required * @param scalarType the custom scalar type of the field * @param conditions list of conditions for this field * @return Field instance representing {@link Type#CUSTOM} */ public static CustomTypeField forCustomType(String responseName, String fieldName, Map<String, Object> arguments, boolean optional, ScalarType scalarType, List<Condition> conditions) { return new CustomTypeField(responseName, fieldName, arguments, optional, scalarType, conditions); }
@Override public void writeCustom(@Nonnull ResponseField.CustomTypeField field, @Nullable Object value) { CustomTypeAdapter typeAdapter = scalarTypeAdapters.adapterFor(field.scalarType()); writeScalarFieldValue(field, value != null ? typeAdapter.encode(value) : null); }
@Override public void writeCustom(@Nonnull ResponseField.CustomTypeField field, @Nullable Object value) { CustomTypeAdapter typeAdapter = scalarTypeAdapters.adapterFor(field.scalarType()); writeScalarFieldValue(field, value != null ? typeAdapter.encode(value) : null); }
@SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"}) @Override public <T> T readCustomType(ResponseField.CustomTypeField field) { if (shouldSkip(field)) { return null; } willResolve(field); Object value = fieldValueResolver.valueFor(recordSet, field); checkValue(field, value); final T result; if (value == null) { resolveDelegate.didResolveNull(); result = null; } else { CustomTypeAdapter<T> typeAdapter = scalarTypeAdapters.adapterFor(field.scalarType()); result = typeAdapter.decode(CustomTypeValue.fromRawValue(value)); checkValue(field, result); resolveDelegate.didResolveScalar(value); } didResolve(field); return result; }
/** * Factory method for creating a Field instance representing a custom GraphQL Scalar type, {@link Type#CUSTOM} * * @param responseName alias for the result of a field * @param fieldName name of the field in the GraphQL operation * @param arguments arguments to be passed along with the field * @param optional whether the arguments passed along are optional or required * @param scalarType the custom scalar type of the field * @param conditions list of conditions for this field * @return Field instance representing {@link Type#CUSTOM} */ public static CustomTypeField forCustomType(String responseName, String fieldName, Map<String, Object> arguments, boolean optional, ScalarType scalarType, List<Condition> conditions) { return new CustomTypeField(responseName, fieldName, arguments, optional, scalarType, conditions); }