question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Transforming input fields

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
MichalLytekcommented, Oct 30, 2019
0reactions
MatthiasKunnencommented, Oct 30, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found