Serverless Functions, also referred to as Functions as a Service (FaaS), enable developers to write and deploy independent pieces of functionality without having to deal with setting up and configuring the server environment.

In that sense, they are similar to microservices, where each function represents one microservice, but again, without the developer having to deal with configuration or deployment overhead. Instead, they can take advantage of the server infrastructures of FaaS providers such as AWS Lambda, Google Cloud Functions or StdLib.

For hooks, it's important to note that we have an input and an output. The input is determined by the operation that we chose, so in our case it's a JSON object that follows the structure of the Customer:

1
2
3
4
5
type CustomerInput {
id: ID! name: String! email: String!}

The output has to be another JSON object and has either one of two fields:

data: When returning the data field we're communicating that the validation and transformation were successful and the data can "proceed".

error: If the validation fails, we can return an error in the JSON object along with a string that represents the error message.

In this article you learned how to setup a hook function using the Graphcool CLI. The function is called every time right before a new customer is created and ensures that the email address that was provided is actually valid and further transforms it to only have lowercase characters.