getSchema
The getSchema method is responsible for returning models and locales in Netlify Create format.
The getSchema
method should fetch the content models from the underlying content source and convert them to an array of Netlify Create models. If the underlying content source supports locales, this method may also fetch the available locales and convert them to an array of Netlify Create locales.
You can extend the Netlify Create Schema
type with custom data using the SchemaContext
generic type and store it in the schema's context
property. Netlify Create will cache this data along with the rest of the Schema
. You can retrieve the cached schema using the cache.getSchema
method, which is passed to the init
method.
Return Value
The getSchema
method should return a Promise
that resolves with a Schema
object containing the following properties:
model
: an array of Netlify Create models represented by theModel[]
type.locales
(optional): an array of Netlify Create locales represented by theLocale[]
type, if the underlying content source supports locales.context
: a custom object as defined by theSchemaContext
generic type. This object can store additional data and will be cached by Netlify Create along with the Schema.
Example
Continuing with the example
for the init method, you can use the apiClient to fetch the content source models and locales, convert them to Netlify Create models, and then return them as a Schema object.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
The convertToStackbitModels
and convertToStackbitLocales
are examples of utility methods that receive arrays of content source models and locales and convert them to Netlify Create models and locales