Schema
Last updated
Last updated
Schema is the heart of Microgen. You can make any application using only schema. You can navigate through the schema menu in order to make some schema, don't forget to Rerun your project after make changes on schema.
By default Microgen generate User schema for you. The User Schema generated are look like this on Raw version:
if you want to add some field inside user, you can add it anytime on schema menu.
String
A String
holds text. This is the type you would use for a username, the content of a blog post or anything else that is best represented as text.
Note: String values are currently limited to 256KB in size on the shared demo cluster. This limit can be increased on other clusters using the cluster configuration.
In queries or mutations, String fields have to be specified using enclosing double quotes: string: "some-string"
.
Integer
An Int
is a number that cannot have decimals. Use this to store values such as the weight of an ingredient required for a recipe or the minimum age for an event.
Note: Int
values range from -2147483648 to 2147483647.
In queries or mutations, Int
fields have to be specified without any enclosing characters: int: 42
.
Float
A Float
is a number that can have decimals. Use this to store values such as the price of an item in a store or the result of complex calculations.
In queries or mutations, Float
fields have to be specified without any enclosing characters and an optional decimal point: float: 42
, float: 4.2
.
Boolean
A Boolean
can have the value true
or false
. This is useful to keep track of settings such as whether the user wants to receive an email newsletter or if a recipe is appropriate for vegetarians.
In queries or mutations, Boolean
fields have to be specified without any enclosing characters: boolean: true
, boolean: false
.
Enums are defined on a service scope.
Like a Boolean an Enum can have one of a predefined set of values. The difference is that you can define the possible values. For example you could specify how an article should be formatted by creating an Enum with the possible values COMPACT
, WIDE
and COVER
.
Note: Enum values can at most be 191 characters long.
In queries or mutations, Enum fields have to be specified without any enclosing characters. You can only use values that you defined for the enum: enum: COMPACT
, enum: WIDE
.
You can also use special fields for specific use case
Default value: set a default value for a field
Unique: set unique for a field
Relation Delete Strategy
CASCADE: when related parent deleted, also delete its child
RESTRICT: can't delete parent, when it had children
SET_NULL: when related parent deleted, set null to the FK relation
File Type: specify whether a field is a file type. It should be followed with String type beforehand, and any schema type that related to this, should set it as hasMany. You need to know this, although you will not see it on the generated code.
Example of Post hasMany Comment, or Comment belongsTo Post.
Example of Post hasMany Category, and Category hasMany Post.
Example of User hasMany User
Example of File Storage usage
Example of Enum usage. This will generate an enum input on create or update.
Example of custom Role usage. For example you want to have 2 admins with different name but with same permissions, and 2 authenticated users with different name.