Transforming input fields
See original GitHub issueI 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.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Input fields - Informatica Documentation
Add input fields to an Input transformation to define the fields that you want to pass into the mapplet. You must add at...
Read more >Transforming Strings - WS Form
Text based fields have a Transform setting that can be used to force the text to be either: Uppercase; Lowercase; Capitalized; Sentence Case....
Read more >Convert input/multi input fields into a Label - formtitan support
Convert input /multi input fields into a Label. Last updated Oct 25 2019. Watch how you can easily change an input field or...
Read more >Transform form Input field into read-only after data is entered
This can be done with some vanilla JavaScript. Here are 2 functions written to lock and unlock the input field. Using the input's...
Read more >PDF Form Fields Transformation - YouTube
Demonstrates how to use fmESignature Link (DocuSign Edition) with PDF Form fields to quickly create a template and have the form fields ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

For future readers - example here 😉 https://github.com/confuser/graphql-constraint-directive/blob/master/index.js
I checked out directives and while they don’t work the same as this proposal, they seem to be able to accomplish what I want. I’ll close this issue.