Relational Mutations

This topic describes relational mutations, also known as nested mutations.

We've given users the ability to create objects wherever they can use an object ID.

For example, suppose you want to use the following blog schema to create a user at the same time you create a post from them:

You could first create the new user, then use that ID to create a new post. Relational mutations give you the ability to do both in one call.

Let's compare creating a user and post using separate mutations versus using a relational mutation.

  1. Create a user with a name and email address:

Which returns the new user's ID:

  1. Now create a post and link it to the new user's ID:

Which returns the post ID:

Instead of two mutations, you can create a post and a user, and link the user to the post, in one mutation:

Which returns something like the following: