Define the content types
How to define content types for external data source.
After understanding the data models, you can define the content types in JSON in Optimizely Graph.
Note
This tutorial uses the non-commercial datasets of IMDb.
The following are defined in the example JSON:
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, an abstract
content type is defined and namedRecord
. It is like a base content type that other content types can extend. In total, Record
is extended with three additional content types, Actor
, Title
, and Rating
.
The field types that can be used are basic GraphQL types like String
, Int
, Float
, Boolean
and [String]
which are used in this tutorial. You can also define object types.
Note
Optimizely Graph also supports
Date
, which is not 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"
}
}
}
}
}
After 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 the username) and App Secret (as the 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 about 1 month ago