Skip to content

unable to specify field level validation for query, mutation arguments #3299

Open
@muvashi

Description

@muvashi

Describe the feature you'd like to request

I am importing a DynamoDB table and creating a custom query/mutation.

https://docs.amplify.aws/react/build-a-backend/data/custom-business-logic/#step-2---configure-custom-business-logic-handler-code

The sample code :-

someAsyncOperation: a.mutation()
    .arguments({
      email: a.string()
    })
    .handler(a.handler.function(signUpForNewsletter).async())
    .authorization((allow) => allow.guest())

On using field level validation on arguments, the following error is observed :-

Field level validation :- https://docs.amplify.aws/react/build-a-backend/data/field-level-validation/

2:04:56 PM [ERROR] [BackendBuildError] Unable to deploy due to CDK Assembly Error
∟ Caused by: [_AssemblyError] Assembly builder failed
∟ Caused by: [AmplifyDataConstructInitializationError] Failed to instantiate data construct
∟ Caused by: [SchemaValidationError] Schema validation failed.


  Directive "@validate" may not be used on ARGUMENT_DEFINITION.
  
  GraphQL request:20:36
  20 |   someAsyncOperation(email: String @validate(type: minLength, value: "1", errorM
     |                                    ^
     | essage: "Content must be at least 1 character long") @validate(type: maxLength, 
  
  Directive "@validate" may not be used on ARGUMENT_DEFINITION.
  
  GraphQL request:20:134
  20 |   someAsyncOperation(email: String @validate(type: minLength, value: "1", errorM
     | essage: "Content must be at least 1 character long") @validate(type: maxLength, 
     |                                                      ^
     | value: "100", errorMessage: "Content must be less than 100 characters") @validat
  
  Directive "@validate" may not be used on ARGUMENT_DEFINITION.
  
  GraphQL request:20:233
  20 |   someAsyncOperation(email: String @validate(type: minLength, value: "1", errorM
     | essage: "Content must be at least 1 character long") @validate(type: maxLength, 
     | value: "100", errorMessage: "Content must be less than 100 characters") @validat
     |                                                                         ^
     | e(type: matches, value: "^[a-zA-Z0-9\\s]+$", errorMessage: "Content must contain 
Resolution: See the underlying error message for more details.

Resolution: Check the Caused by error and fix any issues in your backend code

Describe the solution you'd like

Support field level validation on custom query/mutation.

Describe alternatives you've considered

Currently, the solution is to enforce validation at client end or at resolver level.

Additional context

No response

Is this something that you'd be interested in working on?

  • 👋 I may be able to implement this feature request

Would this feature include a breaking change?

  • ⚠️ This feature might incur a breaking change

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions