Creating an array of fieldsets

THIS PAGE
Creating an array fieldset
Usage in APIs

A lot of times, your graph has a field that needs to hold a list of particularly structured content. Fieldsets can be configured to achieve this functionality.

Screenshot

Once a fieldset is marked as a list, you can make add multiple entries matching the structure of the fields within that fieldset.

Example: You might have a list of cast members in a movie table. Each cast member should have a resource field linked to the actors table and a title field for their role in the movie.

Creating an array fieldset

Screenshot

  1. Click on the + button next to the table node on the graph and select Fieldset.
  2. A new fieldset will be created with a popup for it's properties
  3. Mark the field of type list.
  4. Add fields to the fieldset by clicking on + button next to fieldset node on the graph.

Fieldsets, like fields, must be published in order to be used in the CMS and the APIs.

You can now create CMS entries, the field will be represented as a List Input in the Content Management System. Click on the +Add an item in the list field to open a popup with all the fieldset's field inputs.

Usage in APIs

Creation APIs

When creating an entry programmatically through APIs, pass the an object with all the necessary field keys as key value pairs for the entries that you want.

curl 'https://netflix-api.canonic.dev/movies'
  --request POST
  --header "Content-type: application/json"
  --header "token: TOKEN_HERE"
  --data '{
    "title": "Raj Does Day Off",
    "castMembers": [
      {
        "role": "Lead actor",
        "actor": "1c14b1fc1476c10026961092",
      },
      {
        "role": "Costume designer",
        "actor": "1c14b1fc1476c10026961092",
      },
    ]
  }'

Read APIs

When reading an entry programmatically, the nested entry is fetched automatically and injected into the response.

When using graphql you can select the fields with your GraphQL query. This ensures only the data that you need gets fetched.

{
  "success": true,
  "error": null,
  "data": {
    "_id": "",
    "title": "Raj Does Day Off",
    "cast": [
      {
        "role": "Lead actor",
        "actor": {
          "name": "Aditi Jain",
          "poster": "https://netflix-api.canonic.dev/uploads/5f14b1fc14.png"
        }
      },
      {
        "role": "Costume designer",
        "actor": {
          "name": "Simranjot Singh",
          "poster": "https://netflix-api.canonic.dev/uploads/5f14b1fc14.png"
        }
      }
    ]
  }
}
Did you find what you were looking for?
👍
👎
What went wrong?
Need more help?We have a thriving Discordcommunity that can help you with all things Canonic. →