Lesson 6: Create Objects
Create an Object
Below are some example mutations to create a football_club
, a season
and episodes
and how to link them together.
This first mutation creates a football club called Leyton Orient
. This mutation will return the new object's uid, the title and the slug. You'll need the uid
for subsequent request to create relationships.
All of the objects we create in this step will include the availability we created in Lesson 5: Creating Availability Rules.
mutation {
# Create Object
createFootballClub(
football_club: {
club_name: "Leyton Orient",
slug: "leyton-orient-football-club",
stadium_name: "Brisbane Road",
stadium_location: "London",
league: "EFL League Two",
league_position: 1,
number_of_wins: 22,
number_of_draws: 4,
number_of_losses: 8
availability: {
link: [
"vip-only",
"full-release"
]
}
}
) {
uid
club_name
slug
stadium_name
stadium_location
league
league_position
number_of_wins
number_of_draws
number_of_losses
}
}
Expected result - your UID will be unique.
{
"data": {
"createFootballClub": {
"uid": "01GSD645N6HZRA8658Z1XHYGSS",
"club_name": "Leyton Orient",
"slug": "leyton-orient-football-club",
"stadium_name": "Brisbane Road",
"stadium_location": "London",
"league": "EFL League Two",
"league_position": 1,
"number_of_wins": 22,
"number_of_draws": 4,
"number_of_losses": 8
}
}
}
Add a Season to your new Object
This mutation adds a season
and links it to the football club
.
mutation {
# Create Season
createSeason(
season: {
title: "2021-2022 Season",
slug: "2021-2022-season",
relationships: {
football_clubs: {
link: ["< uid for your football_club >"]
}
},
availability: {
link: [
"vip-only",
"full-release"
]
}
}
) {
uid
title
slug
}
}
Expected result:
{
"data": {
"createSeason": {
"uid": "01GSD6F86J8ZEM2CJPQX6XX640",
"title": "2021-2022 Season",
"slug": "2021-2022-season"
}
}
}
Add Episodes to your Season
Finally, this mutation adds two episodes
to the Season. In our example our episodes are VOD football matches:
mutation {
# Create and add an episode to a season
create_episode_1: createEpisode(
episode: {
title: "Leyton Orient vs West Ham",
slug: "leyton-orient-vs-west-ham",
synopsis: "Leyton Orient beat West Ham in a thrilling FA Cup Third Round Play Off",
episode_number: 1,
relationships: {
seasons: {
link: ["< uid for your season >"]
}
},
availability: {
link: [
"vip-only",
"full-release"
]
}
}
) {
uid
title
slug
}
create_episode_2: createEpisode(
episode: {
title: "Leyton Orient vs Tottenham Hotspur",
slug: "leyton-orient-vs-tottenham-hotspur",
synopsis: "Leyton Orient lose to Spurs in a heroic FA Cup Fourth Round Match",
episode_number: 2,
relationships: {
seasons: {
link: ["< uid for your season >"]
}
},
availability: {
link: [
"vip-only",
"full-release"
]
}
}
) {
uid
title
slug
}
}
Expected result:
{
"data": {
"create_episode_1": {
"uid": "01GSD6HY6Q8E0G0Q02YB520TS6",
"title": "Leyton Orient vs West Ham",
"slug": "leyton-orient-vs-west-ham"
},
"create_episode_2": {
"uid": "01GSD6HYHHZ7JXD496PKDV1Y0Y",
"title": "Leyton Orient vs Tottenham Hotspur",
"slug": "leyton-orient-vs-tottenham-hotspur"
}
}
}
Updated 7 months ago
What’s Next