model
connector.model(fn)
Used to define your data model. This model validates inserted data and Netlify uses it to create the GraphQL schema for your connector.
Takes a function with an object as a parameter. The object contains the following properties:
Parameter | Description |
---|---|
define | Object that contains a number of methods to define models and types on your data model. |
options | Object that contains the configuration values set for options defined using defineOptions() . |
state | Object that contains data stored during init() . |
Learn more about defining your data model.
define
Contains methods to define models and types on your data model.
Method | Description |
---|---|
document() | Used to define a document model. |
enum() | Used to define an enum type. |
inlineEnum() | Used to define an enum type without an explicit name set in the definition. |
inlineObject() | Used to define an object type without an explicit name set in the definition. |
inlineUnion() | Used to define a union type without an explicit name set in the definition. |
locales() | Used to define all available locales in your data source. |
object() | Used to define an object type. |
union() | Used to define a union type. |
document
define.document()
Used to define a document model. Pass in an object with the following properties:
Property | Description |
---|---|
name | String representing the name of the document model. For example, Post or User . |
cacheFieldName | (optional) String representing the field to use for caching each document. |
fields | Object containing each of the document model’s fields. |
localized | (optional) Boolean. Set to true to specify that the model is document-localized. |
Note that every document has an id
that is defined by default. This is the unique ID within your document model type. You don’t need to define an id
property manually in your model, but you will need to set the value when you sync documents.
Usage example
enum
define.enum()
Used to define an enum type. Pass in an object with the following properties:
Property | Description |
---|---|
name | String representing the name of the enum. |
values | Array of objects containing label and value string pairs. |
For unnamed enum types, you can also define the models inline using inlineEnum()
.
Usage example
inlineEnum
define.inlineEnum()
Used to define an enum type without an explicit name set in the definition. Pass in an object with the following property:
Property | Description |
---|---|
values | Array of objects containing label and value string pairs. |
Usage example
inlineObject
define.inlineObject()
Used to define an object type without an explicit name set in the definition. Pass in an object with the following property:
Property | Description |
---|---|
fields | Object containing each of the object’s fields. |
Usage example
inlineUnion
define.inlineUnion()
Used to define a union type without an explicit name set in the definition. Pass in an object with the following property:
Property | Description |
---|---|
types | Array of strings representing object types or document models. |
Usage example
locales
define.locales()
Used to define all available locales in your data source. Pass in an array of objects containing the following properties:
Property | Description |
---|---|
code | String representing the locale code. |
default | (optional) Boolean used to designate a default locale. If not set, the first locale in the array becomes the default. |
Usage example
object
define.object()
Used to define an object type. Pass in an object with the following properties:
Property | Description |
---|---|
name | String representing the name of the object. |
fields | Object containing each of the object’s fields. |
For unnamed object types, you can also define the models inline using inlineObject()
.
Usage example
union
define.union()
Used to define a union type. Pass in an object with the following properties:
Property | Description |
---|---|
name | String representing the name of the union. |
types | Array of strings representing object types or document models. |
For unnamed union types, you can also define the models inline using inlineUnion()
.
Usage example
fields
Object used to define fields for a document model, an object type, or an inline object type. Use an object with the following properties:
Property | Description |
---|---|
{field_name} | Defined using the object property name for that field. You can use any field name except for internal , id , and fields . Review the usage example below for an example of how to set the name. |
type | String or model definition that defines the type of the field. Learn more about field types. |
required | (optional) Boolean. Set to true to mark the field as required. |
list | (optional) Boolean. Set to true to indicate the field is a list. To make the list required, set this property to required instead of true . For example, list: required . |
localized | (optional) Boolean. Set to true to mark the field as localized. |
Field types
The fields on your document model or object type can use the following as a type
:
Type | Description |
---|---|
Built-in scalars | String , Int , Float , Boolean , JSON , and Date . |
Mapped built-in scalars | string (mapped to String ), integer (Int ), number (Float ), boolean (Boolean ), json (JSON ), date (Date ). |
Documents | Another document model you’ve defined. Setting a document model as the type of a field automatically makes that field a relationship field. |
Enums | Enum type that you’ve defined. |
Objects | Object type that you’ve defined. |
Unions | Union type that you’ve defined. |
If you have a type that is only used once, you can define it inline within another field definition. This can be convenient when automatically generating models and types.