DEV Community

Cover image for Creating an email custom scalar to Apollo GraphQL
Kevin Martins
Kevin Martins

Posted on • Originally published at kevinmmartins.Medium

Creating an email custom scalar to Apollo GraphQL

Apollo logo

In this tutorial i will show how to implement an Email custom scalar to Apollo GraphQL.

Implement an email scalar isn’t a hard task but i will show in details.

You must implement the functions __parseValue, __serialize and __parseLiteral.

We need a regex to check the email, in this tutorial i used this one:

Email regex

First we must implement the __parseValue function. Basically we will just test the input type and check the input with our Regex:

__parseValue

After this we will implement the __serialize function , in our example let’s just return the value:

__serialize

And finally lets implement the __parseLiteral function , we will check the literal kind and check our regex with literal value:

__parseLiteral

And that’s it ! Our email custom scalar is done. You can check the complete code and the unit test below:


I hope this helps !

Top comments (0)