Skip to main content

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 case SimpleProfile
  • @createModel is a directive that specifies we are creating a new model
  • accountRelation defines the allowable number of instances per account, where SINGLE limits one instance per account, and LIST allows unlimited instances per account
  • description is a string that describes the model
tip

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 field
  • String! is a scalar that defines displayName is a required (!) string
  • @string is a directive that sets validation rules for the scalar, in our case min and max length
tip

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 →