Define the content types
How to define content types for external data source.
After understanding the data models, you can define this the content types in JSON in Optimizely Graph.
Note
This tutorial uses the non-commercial datasets of IMDb.
In the following JSON, label
, languages
, links
and contentTypes
is defined:
label
– Metadata to explain what kind of source it is.languages
– Used to explain whichlocale
should be supported.links
– Used to create joins between instances of content types.contentTypes
– Consists of the description of the schemas.
In the content types, we see that we defined an abstract
content type called Record
. It is like a base content type that can be extended by other content types. In total, Record
has been extended with three additional content types:
Actor
Title
Rating
The field types that can be used are basic GraphQL types like String
, Int
, Float
, Boolean
and [String]
which are used here. You can also define object types. Optimizely Graph also supports Date
, which has not been used in this tutorial.
{
"label": "IMDB",
"languages": [
"en"
],
"links": {
"DEFAULT": {
"from": "knownForTitles",
"to": "tconst"
},
"TITLES": {
"from": "tconst",
"to": "tconst"
},
"TITLE_TO_ACTOR": {
"from": "tconst",
"to": "knownForTitles"
}
},
"contentTypes": {
"Record": {
"abstract": true,
"contentType": [],
"properties": {
"ContentType": {
"type": "[String]"
}
}
},
"Actor": {
"contentType": [
"Record"
],
"properties": {
"nconst": {
"type": "String"
},
"tconst": {
"type": "String"
},
"ContentType": {
"type": "[String]"
},
"primaryName": {
"type": "String",
"searchable": true
},
"birthYear": {
"type": "Int"
},
"deathYear": {
"type": "Int"
},
"primaryProfession": {
"type": "[String]",
"searchable": true
},
"knownForTitles": {
"type": "[String]"
}
}
},
"Title": {
"contentType": [
"Record"
],
"properties": {
"tconst": {
"type": "String"
},
"ContentType": {
"type": "[String]"
},
"titleType": {
"type": "String"
},
"primaryTitle": {
"type": "String",
"searchable": true
},
"originalTitle": {
"type": "String"
},
"isAdult": {
"type": "Boolean"
},
"startYear": {
"type": "Int"
},
"endYear": {
"type": "Int"
},
"runtimeMinutes": {
"type": "Int"
},
"genres": {
"type": "[String]",
"searchable": true
}
}
},
"Rating": {
"contentType": [
"Record"
],
"properties": {
"tconst": {
"type": "String"
},
"ContentType": {
"type": "[String]"
},
"averageRating": {
"type": "Float"
},
"numVotes": {
"type": "Int"
}
}
}
}
}
Once you have defined the content types of the data from your external source, you can send this to Optimizely Graph, so it can generate the GraphQL schema types for you. You can use basic authentication to simplify testing, where you can get the token by using your App Key (as user name) and App Secret (as password).
curl --location --request PUT 'https://cg.optimizely.com/api/content/v3/types?id=imdb' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <Token>' \
--data @content_type.json
Updated 5 months ago