Models
The models
are part of the MVC(model–view–controller) architectural pattern, being the representation of the data layer. In RecifeJs model representation will also be used to define the graphql types.
Creating Model
Use the CLI for create a new model:
recife model User
or
npx recife-cli model User
The model will be created in the src/models
directory with the name UserModel.ts
. And it will have the following content:
import { Type } from "recife";
@Type()
class UserModel {
id?: string;
}
export default UserModel;
Using the GraphQL
RecifeJs uses decorators to identify the class of the models that will represent the graphql types. See more about decorators here.
See the example below:
import { Type, Field } from "recife";
@Type()
class UserModel {
id: string;
name: string;
cash?: Number;
@Field("Int")
age: Number;
createdAt: Date;
updatedAt?: Date;
}
export default UserModel;
From this model, the GraphQL type will be created. See how the type looks:
type User {
id: String!
name: String!
cash: Float
age: Int!
createdAt: Date!
updatedAt: Date
}
Heritage
to do
Field decorator
to do