Manage Object Types

Create New Object Type

This example creates a new Object Type called tv_show. It also creates and assigns a number of fields and relationships to existing objects.

📘

Please note that adding an object will require you to activate a new version of the schema before you are able to start using it.

mutation CreateObjectType {
  createObjectType(
    object_types: [
      {
        name: "tv_show"
        fields: [
          { name: "name", operation: CREATE, type: STRING },
          { name: "number_of_episodes", operation: CREATE, type: INTEGER },
          { name: "number_of_seasons", operation: CREATE, type: INTEGER },
          { name: "synopsis", operation: CREATE, type: STRING },
          { name: "popularity", operation: CREATE, type: FLOAT }
        ]
        relationships: [
          {
            to_class: Season
            relationship_name: "seasons"
            reverse_relationship_name: "tv_shows",
            operation: CREATE
          },
          {
            to_class: Episode
            relationship_name: "episodes"
            reverse_relationship_name: "tv_shows",
            operation: CREATE
          },
          {
            to_class: Rating
            relationship_name: "ratings"
            reverse_relationship_name: "tv_shows",
            operation: CREATE
          },
          {
            to_class: Genre
            relationship_name: "genres"
            reverse_relationship_name: "tv_shows",
            operation: CREATE
          },
          {
            to_class: SkylarkImage
            relationship_name: "images"
            reverse_relationship_name: "tv_shows",
            operation: CREATE
          },
          {
            to_class: SkylarkAsset
            relationship_name: "assets"
            reverse_relationship_name: "tv_shows",
            operation: CREATE
          },
        ]
      }
    ]
  ) {
    version
    messages
  }
}

Field Type Mapping

When creating object type and setting up new fields, you'll need to specify a field type. Here's a list of the types Skylark supports:

string
integer
float
boolean
enum
datetime
date
email
ip_address
json
phone
time
timestamp
url

Create Objects and Fields

Here you can create a new object along with fields and relationships for that object.

The create object mutation has the following arguments:

ArgumentDescription
nameThe name of the object to edit, e.g Episode
has_imagesThis is a shortcut to easy add an image relationship to your object
set_contentWhether this object can appear as content in sets
fieldsAn array of fields to edit
relationshipsAn array of relationships to edit

The input for the fields and relationships arguments are the same as the edit fields and edit relationships mutations, except the from_class field in each relationship is not required as it defaults to the object you are creating.

This example shows creating a new object type complete with 3 new fields and a relationship to the Brand object.

mutation CreateObjectType {
  createObjectType(
    object_types: [
      {
        name: "spin-off"
        fields: [
          { name: "title", operation: CREATE },
          { name: "synopsis", operation: CREATE },
          { name: "url", operation: CREATE, type: URL },
        ]
        relationships: [
          {
            to_class: Brand
            relationship_name: "brands"
            reverse_relationship_name: "spin-offs",
            operation: CREATE
          }
        ]
      }
    ]
  ) {
    version
    messages
  }
}

Response:

{
  "data": {
    "editObjectTypeConfiguration": {
      "version": 2,
      "messages": [
        "Creating new version (2) from active version",
        "Adding field title to Spin-Off",
        "Adding field synopsis to Spin-Off",
        "Adding field url to Spin-Off",
        "Added relationship brands to object Brand from type Spin-Off",
        "Added relationship spin-offs to object Spin-Off from type Brand"
      ]
    }
  }
}

Delete object type

This example shows deleting multiple object types.

mutation DeleteObjectType {
  editObjectTypeConfiguration(
    objects: [
      {
        operation: DELETE,
        name: "spin-off"
      },
      {
        operation: DELETE,
        name: "tv_show"
      }
    ]
  ) {
    version
    messages
  }
}

📘

How deleting types effects stored data

When you delete an object type from the schema, all the objects created remain in the database. That means if you delete an type, activate the version, then rollback to the previous version, all the objects you created with that type will still be available.