graphql-input-string icon indicating copy to clipboard operation
graphql-input-string copied to clipboard

Getting the field name to return in an error

Open Secular12 opened this issue 6 years ago • 0 comments

I am trying to get the name of the field that was caused the error and to return that in the error

TrimmedString: GraphQLInputString({
    name: 'TrimmedString',
    error (info) {
        // somewhere in here get the name of the input field
        // For instance if the field was email I can assign it to a fieldName variable and use it in here:
        throw new GraphQLError(`The field ${fieldName} must not be empty.`)
    }
    trim: true
 }),

Secular12 avatar Nov 08 '19 00:11 Secular12