How to check valid email address using @email directive

In the previous post, we have seen how to check past and future dates using Hypi Directives.(@past and @future)

Now we will check how to check a valid email address using @email directive.

Again a brief info on Hypi Directives:

  • Hypi directives help to customise the behaviour of the data fields.
  • @ character depicts the Hypi directive. It is followed by a series of characters.
  • A directive may have a list of optional named arguments.
  • Disable directive by adding # in front of it.

Let’s check the @email directives!
email: String @email

  • Use the @email directive to check if the field’s value is a valid email address.
  • The directive returns an error if the inserted string is not a valid email address.

We will work with the below schema.

type DirectiveObj {
  emailStr: String @email
  emailStr1: String @email
  emailStr2: String @email
}

Sample Query

Let’s see how the @email directive works.

mutation {
    upsert(values: {
            DirectiveObj: {
              emailStr:"hypi",
              emailStr1:"user@hypi"
              emailStr2:"user@hypi.in"
            }
        }
    ) {
        id
    }
}
#result
{
  "data": {
    "upsert": [
      {
        "id": "01FNNY46DW20W0XTHYQ9AVHSTH"
      }
    ]
  },
  "errors": [
    {
      "message": "'hypi' is not a valid email address",
      "extensions": {}
    },
    {
      "message": "'user@hypi' is not a valid email address",
      "extensions": {}
    }
  ]
}

Check the POSTMAN collection for the @email directive in different programming languages! Click </> and choose the programming language of your choice.
Don’t forget to insert your own Authorization key and Hypi Domain under Headers to test the results!

Run in Postman