-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
Description
I find myself short of an easy way to perform reusable transformation on input fields.
Say there is the following input object:
export const AddressInputType = new GraphQLInputObjectType({
name: 'AddressInput',
fields: () => ({
name: {
type: new GraphQLNonNull(GraphQLString),
},
}),
});I would like to be able to do the following:
export const trim = (source, info) => source[info.fieldName].trim();
export const toUpperCase = (source, info) => source[info.fieldName].toUpperCase();
export const AddressInputType = new GraphQLInputObjectType({
name: 'AddressInput',
fields: () => ({
name: {
type: new GraphQLNonNull(GraphQLString),
transform: [
trim,
toUpperCase,
],
},
}),
});Returning undefined from a transform function should remove the field from the source object.
When to transform? I believe the transformation should occur after the type is parsed although arguments can be made to apply the transform before parsing. A potential solution is to have a transformBefore and a transformAfter property.
It should be possible to throw an error in the transform function. This should be handled similar to throwing an error in the type parser.