Creating a Record
Create a single record from the API
Creating new records is a vital operation when interacting with your database. With Noloco's dynamic GraphQL API, you can smoothly initiate new entries using GraphQL mutations. This guide will show you the steps to create a new record using the API.
Creating a new record with the API
When you wish to create a new record, you will use a GraphQL mutation. The general format is mutation create<tableName>
, where <tableName>
is the name of the table where you want to add the record.
Examples:
For adding a new project:
mutation createProjects
.For registering a new user:
mutation createUser
.
Providing Field Values
When creating a record, you can specify values for any of the table's fields. While all the fields are optional, any fields marked as 'unique' must be provided to ensure data integrity.
Example:
In the above example, a new user is being created with specific values for the email
, firstName
, lastName
and age
fields
Choosing Response Fields
Just as with fetching records, you can decide what fields and values you want to return in the response after creating a record. This is useful to confirm that the record has been created with the intended values or to immediately fetch additional data from the new record.
Example:
After creating the project, the response will contain the id
, name
, and createdAt
fields, providing immediate feedback about the new record.
Conclusion
Using Noloco's dynamic GraphQL API, creating new records is efficient and flexible. The mutation structure allows for precise data entry, and the option to select return fields ensures you get immediate and relevant feedback on the records you add. With this approach, you can ensure that your data is consistently accurate and up-to-date.
Last updated