Lesson 3: Modify Your Data Model
Skylark comes with a pre-configured schema that represents the fundamentals of a streaming platform that is geared towards entertainment.
However, if your product requires a schema that is slightly or even vastly different, Skylark offers the flexibility to make and view changes to your schema quickly and easily.
All schema changes are versioned, enabling you to create new versions, observe changes in progress, and roll back or forward versions as needed.
Create a New Object Type
Let's start out by adding a new Object Type to your data model.
This example creates a new Object Type called football_club. It also creates and assigns a number of fields and relationships to existing objects.
mutation CreateObjectType {
createObjectType(
object_types: [
{
name: "football_club"
fields: [
{ name: "club_name", operation: CREATE, type: STRING },
{ name: "stadium_name", operation: CREATE, type: STRING },
{ name: "stadium_location", operation: CREATE, type: STRING },
{ name: "league", operation: CREATE, type: STRING },
{ name: "league_position", operation: CREATE, type: INTEGER },
{ name: "number_of_wins", operation: CREATE, type: INTEGER },
{ name: "number_of_draws", operation: CREATE, type: INTEGER },
{ name: "number_of_losses", operation: CREATE, type: INTEGER }
]
relationships: [
{
to_class: Season
relationship_name: "seasons"
reverse_relationship_name: "football_clubs",
operation: CREATE
},
{
to_class: Episode
relationship_name: "episodes"
reverse_relationship_name: "football_clubs",
operation: CREATE
},
{
to_class: Rating
relationship_name: "ratings"
reverse_relationship_name: "football_clubs",
operation: CREATE
},
{
to_class: SkylarkImage
relationship_name: "images"
reverse_relationship_name: "football_clubs",
operation: CREATE
},
{
to_class: SkylarkAsset
relationship_name: "assets"
reverse_relationship_name: "football_clubs",
operation: CREATE
},
]
}
]
) {
version
messages
}
}
And here's the resulting message:
{
"data": {
"createObjectType": {
"version": 4,
"messages": [
"Creating new version (4) from active version",
"Created new object: FootballClub",
"Adding field club_name to FootballClub",
"Adding field stadium_name to FootballClub",
"Adding field stadium_location to FootballClub",
"Adding field league to FootballClub",
"Adding field league_position to FootballClub",
"Adding field number_of_wins to FootballClub",
"Adding field number_of_draws to FootballClub",
"Adding field number_of_losses to FootballClub",
"Added relationship seasons to object Season from type FootballClub",
"Added relationship football_clubs to object FootballClub from type Season",
"Added relationship episodes to object Episode from type FootballClub",
"Added relationship football_clubs to object FootballClub from type Episode",
"Added relationship ratings to object Rating from type FootballClub",
"Added relationship football_clubs to object FootballClub from type Rating",
"Added relationship images to object SkylarkImage from type FootballClub",
"Added relationship football_clubs to object FootballClub from type SkylarkImage",
"Added relationship assets to object SkylarkAsset from type FootballClub",
"Added relationship football_clubs to object FootballClub from type SkylarkAsset"
]
}
}
}
Activate Your New Schema Version
In order to start using your new object as part of the wider data model you'll need to activate it using a query like this:
mutation {
activateConfigurationVersion(version: 2) {
messages
}
}
Result:
{
"data": {
"activateConfigurationVersion": {
"messages": [
"Replacing version 1",
"Activated version 2"
]
}
}
}
Changes Now Reflected In Your Schema
Note that the GraphQL schema now contains new queries and mutations for the new Object Type:
getFootballClub
listFootballClub
createFootballClub
deleteFootballClub
updateFootballClub
Search
After activating the new schema, the new object type is searchable:
Updated 4 months ago