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 MyMutation {
  createObjectConfiguration(
    objects: [
      {
        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:

  • name: The name of the object to edit, e.g Episode
  • has_images: This is a shortcut to easy add an image relationship to your object
  • set_content: Whether this object can appear as content in sets
  • fields: An array of fields to edit
  • relationships: An 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 complete with 3 new fields and a relationship to the Brand object.

mutation MyMutation {
  createObjectConfiguration(
    objects: [
      {
        name: "example_object"
        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: "example_objects",
            operation: CREATE
          }
        ]
      }
    ]
  ) {
    version
    messages
  }
}

Response:

{
  "data": {
    "createObjectConfiguration": {
      "version": 2,
      "messages": [
        "Creating new version (2) from active version",
        "Adding field title to ExampleObject",
        "Adding field synopsis to ExampleObject",
        "Adding field url to ExampleObject",
        "Added relationship brands to object Brand from type ExampleObject",
        "Added relationship example_objects to object ExampleObject from type Brand"
      ]
    }
  }
}