-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Hi guys,
I have spent some time looking for a solution on how to implement data validation in graphql using directives. The idea seems very nice and clear: schema directives define validation rules to be applied to the data, eg
input ConsumerData {
name: String @length(min: 1, max: 20)
}
However current approach described in the documentation refers to output types of directives only and suggests usage of Consumer<GraphQLFieldDefinition.Builder> together with GraphQLFieldDefinition.dataFetcher.
Applying the same approach to GraphQLInputObjectField wouldn't work since GraphQLInputObjectField doesn't have any kind of data transformer.
Would it make sense to add something like
interface DataTransformer<T> {
public T transform(T value)
}to GraphQLInputObjectField for the purpose of usage of directives? This could be used in ValuesResolver.coerceValueAstForInputObject.
To supply a DataTransformer to ValuesResolver one could use the same wiring approach as one currently used to update dataFetcher on GraphQLFieldDefinition.