Create Objects
Introduction
Creating objects is handled by the create<Object Name>
mutation. For example: createEpisode
. For convenience in this document, this mutation will be generalised as createObject
.
Creating a new object in Skylark will do the following:
- Create global version 1
- Create language version 1 for the language specified (or the default language)
- Create a compiled object, combining the global and language data
- Create availability slots if they have been defined in the input
For adding availability see here.
For adding relationships see here.
Create Basic Objects
Here's a recipe for creating an object
:
In this example we're creating an Episode Object:
mutation MyMutation {
createEpisode(
language: "en-GB",
episode: {
episode_number: 1,
title: "The Mandalorian",
synopsis: "An armored bounty hunter takes on a well-paying yet cryptic assignment."
}) {
# Return fields
uid
title
synopsis
}
}
This is the response:
{
"data": {
"createEpisode": {
"uid": "4220f2b2-db6c-4c26-b870-204066bf534a",
"title": "The Mandalorian",
"synopsis": "An armored bounty hunter takes on a well-paying yet cryptic assignment."
}
}
}
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.gEpisode
has_images
: This is a shortcut to easy add an image relationship to your objectset_content
: Whether this object can appear ascontent
in setsfields
: An array of fields to editrelationships
: 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"
]
}
}
}
Updated about 2 months ago