Examples
Explore common output patterns and generated code
Generated Folder Structure
build/
- package.json
- tsconfig.json
- dbConfig.ts
| adminPortal/
- ...adminPortalFiles
| app/
| ui/
- button.tsx
- modal.tsx
- input.tsx
- ...componentFiles
| hooks/
| <endpointBucketN>/
- ...hookFiles
| api/
{if (graphQL)}
| queries/
| <endpointBucketN>/
- ...queryFiles
| mutations/
| <endpointBucketN>/
- ...mutationFiles
| cicd/
- ...cicdFlavorFiles
| cloudOps/
- ...cloudOpsFiles
| enums/
- ...enumFiles
| migrations/
- ...migrationFiles
| seeds/
- ...seedFiles
| src/
| @types/
| dataServices/
| tables/
| typedefs/
| config/
- ...configFiles
| database/
- ...dbFiles
| dataServices/
| <endpointBucketN>/
- ...dataServiceFiles
{if (graphQL)}
| resolvers/
| <endpointBucketN>/
- ...resolverFiles
| typedefs/
| <endpointBucketN>/
- ...typedefFiles
{if (rest)}
| endpoints/
| <endpointBucketN>/
- ...endpointFiles
| utils/
Generated Resolver
// build/api/mutations/misc/updateManyOrganization.ts
export const updateManyOrganization = async (_, args, ctx) => {
return ctx.db.organization.updateMany({
where: { id: { in: args.ids } },
data: args.data,
});
};
Generated Controller
// build/api/controllers/user/createUser.ts
export const createUser = async (
req: Request,
res: Response<User | { success: false; message: string }>,
) => {
const args = req.body;
try {
const requiredFields = ['password_hash', 'email'];
for (const field of requiredFields) {
if (!args[field]) {
return res
.status(400)
.send({ success: false, message: `Missing ${field} param` });
}
}
const record = await writeUser(args);
res.status(200).json(record);
} catch (error) {
console.error('Error: create of createUser:', error);
res.status(500).send({
success: false,
message: 'Failed to create createUser',
});
}
};;
Generated Data Service
export const writeUser = async (args: WriteUserArgs): Promise<User | undefined> => {
const resp = await runTransaction<User[]>((trx) =>
trx('user').insert(args).returning('*'),
);
return resp && resp[0] ? resp[0] : undefined;
};
Generated Typedef
export const userObjectType = new GraphQLObjectType({
name: 'userObjectType',
description: 'Generated objectTypes for user',
fields: {
id: { type: new GraphQLNonNull(GraphQLString) },
username: { type: GraphQLString },
email: { type: GraphQLString },
phone: { type: GraphQLString },
password_hash: { type: new GraphQLNonNull(GraphQLString) },
image: { type: GraphQLString },
last_login: { type: GraphQLString },
created_at: { type: GraphQLString },
updated_at: { type: GraphQLString },
deleted_at: { type: GraphQLString },
},
});
Generated Model
// src/models/user.ts
export const UserModel = sequelize.define(
'UserModel',
{
username: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
field: 'username',
},
email: {
type: DataTypes.STRING(255),
allowNull: true,
unique: true,
field: 'email',
},
phone: {
type: DataTypes.STRING(20),
allowNull: true,
unique: true,
field: 'phone',
},
password_hash: {
type: DataTypes.TEXT,
field: 'password_hash',
},
image: {
type: DataTypes.STRING(255),
allowNull: true,
field: 'image',
},
last_login: {
type: DataTypes.DATE,
allowNull: true,
field: 'last_login',
},
id: {
type: DataTypes.UUID,
primaryKey: true,
unique: true,
field: 'id',
},
created_at: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: Sequelize.literal('NOW()'),
field: 'created_at',
},
updated_at: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: Sequelize.literal('NOW()'),
field: 'updated_at',
},
deleted_at: {
type: DataTypes.DATE,
allowNull: true,
field: 'deleted_at',
},
},
{
tableName: 'user',
freezeTableName: true,
timestamps: true,
paranoid: true,
underscored: true,
indexes: [
{
name: 'idx_user_username',
fields: ['username'],
unique: false,
},
{
name: 'idx_user_email',
fields: ['email'],
unique: false,
},
{
name: 'idx_user_phone',
fields: ['phone'],
unique: false,
},
],
},
);
/* Define associations*/
UserModel.belongsToMany(OpportunityApplicationModel, {
through: 'opportunity_application_log',
foreignKey: 'id',
otherKey: 'id',
as: 'manyOpportunityApplication'
});
UserModel.belongsToMany(CourseModel, {
through: 'course_assignment',
foreignKey: 'id',
otherKey: 'id',
as: 'manyCourse'
});
UserModel.belongsToMany(OrganizationModel, {
through: 'organization_user_metric',
foreignKey: 'id',
otherKey: 'id',
as: 'manyOrganization'
});
UserModel.belongsToMany(OrganizationModel, {
through: 'ai_metric',
foreignKey: 'id',
otherKey: 'id',
as: 'manyOrganization'
});
UserModel.belongsToMany(OrganizationModel, {
through: 'chat_metric',
foreignKey: 'id',
otherKey: 'id',
as: 'manyOrganization'
});
Generated React Hook
// build/app/hooks/user/useFindManyUser.ts
import { useQuery } from '@apollo/client';
import { FIND_MANY_USER } from '@/graphql/user';
export function useFindManyUser(variables) {
return useQuery(FIND_MANY_USER, { variables });
}
UI Component
// build/ui/button.tsx
export function Button({ className, ...props }) {
return <button className={cn('px-4 py-2 rounded', className)} {...props} />;
}