GraphQL Cookbook

Creating an object

8min

Creating an object through the Parse GraphQL API

Problem

You want to create a new object in your database through the Parse GraphQL API.

Solution

Using the parse GraphQL, there are two different ways to create a new object in your database:

  • Using generic mutation - - this is the mutation that you must use if you do not have already created your object’s class.
  • Using class mutation - this is the recommended mutation if you have already created your object’s class.

Version Information

Depending on the version of Parse you choose to run, the GraphQL queries, mutations and results will be slightly different. Please choose the correct example along with the Parse version you are running.

Using generic mutation

When you use the create generic mutation, Parse Server behaves like a schemaless database. It means that you do not need to define your object’s class in your application’s schema beforehand. You just need to send your object’s data, and Parse Server will not only store it, but also learn from it, and automatically create a new class in your application’s schema.

Therefore, the objects’ create generic mutation is the method that you must use for creating a new object if you do not have already created your object’s class. You can also use this mutation for creating an object of pre-existing classes, but, for these cases, we recommend using the class mutation.

Class:

Request
Response


Object:

Request
Response


Using class mutation

Once you have already created your object’s class in your application’s schema (for instance, using the generic mutation), Parse Server instantly adds to your GraphQL API a new create<ClassName> mutation to create a new object of this class.

Therefore, the object’s class mutation is the recommended method for creating a new object if you have already created your object’s class. Since this mutation knows your class’ data, it will automatically make available for you additional features like code auto-complete and validation. You also don’t need to specify the data types when sending dates, pointers, relations, files, geo points, polygons, or bytes through the class create mutation.

This example will only work if you have already created your object’s class. You can create a class using the generic mutation.

Request
Response


Older Parse Server Versions

Generic mutation

Class:

Request
Response


Object:

Request
Response


Class mutation

Parse Server 3.9.0
Result Parse 3.9.0


Generic mutation:

Parse Server 3.8.0
Result Parse 3.8.0


Class mutation:

Parse Server 3.8.0
Result Parse 3.8.0


Generic mutation:

Parse Server 3.7.2
Result Parse 3.7.2


Class mutation:

Parse Server 3.7.2
Result Parse 3.7.2