Introduction to Modeling
Learn the basics of creating a new data model.
Setup
Create a new .graphql
file in your project directory to store your model(s).
For example, let’s create a file called my-schema.graphql
. Inside, we’re going to create a model to store a very simple user profile:
type SimpleProfile @createModel(accountRelation: SINGLE, description: "Very basic profile") {
displayName: String! @string(minLength: 3, maxLength: 50)
}
Metadata
Let’s look into the metadata properties of your new model:
type SimpleProfile @createModel(accountRelation: SINGLE, description: "Very basic profile")
Where:
type
defines the name for your model, in our caseSimpleProfile
@createModel
is a directive that specifies we are creating a new modelaccountRelation
defines the allowable number of instances per account, whereSINGLE
limits one instance per account, andLIST
allows unlimited instances per accountdescription
is a string that describes the model
Model names and descriptions are used in the Model Catalog. Aim for short and descriptive to improve discovery and reuse.
Schema
Model schemas are written using the GraphQL Schema Definition Language (SDL). Let’s look at the schema of our new model. It’s a shape that only defines a single field (key) and scalar (value):
{
displayName: String! @string(minLength: 3, maxLength: 50)
}
Where:
displayName
is a fieldString!
is a scalar that definesdisplayName
is a required (!
) string@string
is a directive that sets validation rules for the scalar, in our case min and max length
This is a very basic schema. Your schemas can contain more than one field and include various relations. See Schemas next.
Next Steps
To use your new model in your application, you will need to create a Composite →