The process of sending data to server is called mutation. Defining it is pretty similar on how you’ve defined the query.
Let me explain this snippet, piece by piece:
#1: Defines a mutation class. Right after, you define the output of the mutation, the data the server can send back to the client. The output is defined field by field for learning purposes. In the next mutation you’ll define them as just one.
#2: Defines the data you can send to the server, in this case, the links’
#3: The mutation method: it creates a link in the database using the data sent by the user, through the
descriptionparameters. After, the server returns the
CreateLinkclass with the data just created. See how this matches the parameters set on
#4: Creates a mutation class with a field to be resolved, which points to our mutation defined before.
This will make sure our schema knows the mutation created.
Time to play! In the GraphiQL interface, enter the following data and see how a link gets created:
After, try to query the data again, you should see the new link.