
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@panter/crud
Advanced tools
In the modern web development landscape, CRUD operations form the backbone of many applications. The @panter/crud library seamlessly integrates with Nest.js and Mikro-Orm to provide developers with a powerful tool to automatically generate a GraphQL API t
In the modern web development landscape, CRUD operations form the backbone of many applications. The @panter/crud library seamlessly integrates with Nest.js and Mikro-Orm to provide developers with a powerful tool to automatically generate a GraphQL API tailored for CRUD operations.
The @panter/crud library is a lightweight yet robust solution designed for Nest.js applications. By leveraging the power of Mikro-Orm entities and GraphQL schemas, it automates the creation of GraphQL endpoints for standard CRUD operations. This means less boilerplate code, consistent API patterns, and faster development cycles.
Auto-Generated Resolvers: Based on your Mikro-Orm entities and GraphQL schema, the library can automatically generate resolvers for:
FindOneResolver)FindManyResolver)CreateOneResolver)UpdateOneResolver)DeleteOneResolver)@CrudField decorator, developers can easily control the visibility and behavior of
entity fields during CRUD operations. For instance, certain fields can be hidden during creation or update processes.yarn add @panter/crud
Consider a simple User entity:
import { Entity, PrimaryKey, Property } from '@mikro-orm/postgresql';
import { Field, ObjectType } from '@nestjs/graphql';
import { CrudField } from '@panter/crud';
@Entity()
@ObjectType()
export class User {
static readonly string entityName = "User" as const;
@CrudField({ showConnect: true, showDisconnect: true })
@Field()
@PrimaryKey({ autoincrement: true })
id!: number;
@Field()
@Property()
name!: string;
}
With just this entity definition and the power of @panter/crud, a comprehensive GraphQL API is generated, allowing clients to fetch, create, update, and delete users with ease.
Resolver:
import { FindOneResolver } from '@panter/crud';
@Resolver(() => User)
export class FindOneUserResolver extends FindOneResolver(User) {}
Schema:
type User {
id: Float!
name: String!
}
type Query {
user(where: EntityIdInput): User
}
input EntityIdInput {
id: String!
}
Resolver:
import { FindManyResolver } from '@panter/crud';
@Resolver(() => User)
export class FindManyUserResolver extends FindManyResolver(User) {}
Schema:
type User {
id: Float!
name: String!
}
type Query {
users(
where: UserWhereInput
orderBy: [UserOrderByInput!]
skip: Int
take: Int
): [User!]!
usersCount(
where: UserWhereInput
orderBy: [UserOrderByInput!]
skip: Int
take: Int
): Int!
}
input UserWhereInput {
AND: [UserWhereInput!]
OR: [UserWhereInput!]
NOT: [UserWhereInput!]
id: IntFilter
name: StringFilter
}
input IntFilter {
equals: Float
gt: Float
gte: Float
lt: Float
lte: Float
}
input StringFilter {
equals: String
in: [String!]
nin: [String!]
contains: String
gt: String
gte: String
lt: String
lte: String
fulltext: String
mode: SringQueryMode
}
enum SringQueryMode {
default
insensitive
}
input UserOrderByInput {
id: SortOrder
name: SortOrder
}
enum SortOrder {
asc
desc
}
Resolver:
import { CreateOneResolver } from '@panter/crud';
@Resolver(() => User)
export class CreateOneUserResolver extends CreateOneResolver(User) {}
Schema:
type User {
id: Float!
name: String!
}
type Mutation {
createOneUser(data: UserCreateInput): User!
}
input UserCreateInput {
name: String
}
Resolver:
import { UpdateOneResolver } from '@panter/crud';
@Resolver(() => User)
export class UpdateOneUserResolver extends UpdateOneResolver(User) {}
Schema:
type User {
id: Float!
name: String!
}
type Mutation {
updateOneUser(data: UserUpdateInput, where: EntityIdInput!): User!
}
input UserUpdateInput {
name: StringInput
}
input StringInput {
set: String
}
input EntityIdInput {
id: String!
}
Resolver:
import { DeleteOneResolver } from '@panter/crud';
@Resolver(() => User)
export class DeleteOneUserResolver extends DeleteOneResolver(User) {}
Schema:
type User {
id: Float!
name: String!
}
type Mutation {
deleteOneUser(where: EntityIdInput): User!
}
input EntityIdInput {
id: String!
}
The ObjectRelationResolver is tailored to generate GraphQL resolvers for entity relationships where one entity relates to multiple others. Instead of merely fetching these related entities, the resolver provides enhanced capabilities, allowing clients to filter and paginate through the related entities seamlessly.
Resolver:
@Module({
imports: [MikroOrmModule.forFeature({ entities: [Group] })],
providers: [
MaterialsDepotFindOneResolver,
...ObjectRelationResolvers(MaterialsDepot),
],
})
export class GroupModule {}
Schema:
type Group {
id: Float!
name: String!
description: String!
founders(where: UserWhereInput, orderBy: [UserOrderByInput!], skip: Int, take: Int): [User!]!
coordinator(where: UserWhereInput, orderBy: [UserOrderByInput!], skip: Int, take: Int): [User!]
finance(where: UserWhereInput, orderBy: [UserOrderByInput!], skip: Int, take: Int): [User!]
}
input UserWhereInput {
AND: [UserWhereInput!]
OR: [UserWhereInput!]
NOT: [UserWhereInput!]
id: IntFilter
name: StringFilter
}
input UserOrderByInput {
id: SortOrder
name: SortOrder
}
...
The CrudField decorator is used to control the visibility and behavior of entity fields during CRUD operations.
Crud Field is not responsable for visibility on the object return by the mutations and queries. For this you can use
the @Field decorator
from @nestjs/graphql. This is subject to change in the future.
Api Options:
showConnect: If set to true, the field will be hidden from the create operation, so the field showDisconnectbe set during
creation.hideUpdate: If set to true, the field will be hidden from the update operation, so the field cannot be updated.hideWhere: If set to true, the field will be hidden from the where input type, so the field cannot be filtered.isEmbedded: If set to true, the field will be embedded in the entity.fieldOptions: An object containing additional options for the field. This object is passed directly to the @Field
decorator from @nestjs/graphql.relation:
showConnect: If set to true, the relation can be connected by primary key.showCreate: If set to true, the relation can be created with all it's fields.showUpdate: If set to true, the relation can be updated with all it's fields.showDisconnect: If set to true, the relation can be disconnected by primary key.CRUD_DEFAULT_HIDE_RELATION_MODIFIER: If set to false, create and update modifiers will be shown if nothing else is set.CRUD_DEFAULT_HIDE_CONNECT_RELATION_MODIFIER: If set to false, connect and disconnect modifiers will be shown if nothing else is set.FAQs
In the modern web development landscape, CRUD operations form the backbone of many applications. The @panter/crud library seamlessly integrates with Nest.js and Mikro-Orm to provide developers with a powerful tool to automatically generate a GraphQL API t
We found that @panter/crud demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.