
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@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/core';
import { Field, ObjectType } from '@nestjs/graphql';
import { CrudField } from '@panter/crud';
@Entity()
@ObjectType()
export class User {
@CrudField({ hideCreate: true, hideUpdate: 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.
Relationship Detection: The ObjectRelationResolver identifies relationships within the Mikro-Orm entities where one entity has multiple relations (e.g., one-to-many or many-to-many relationships).
Resolver Generation: For each detected relationship, the resolver automatically generates GraphQL endpoints. These endpoints are not just for fetching the related entities but also offer advanced querying capabilities.
Filtering and Pagination: The generated endpoints come equipped with filtering and pagination functionalities. This allows clients to retrieve a subset of related entities based on specific criteria or paginate through large sets of related entities.
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:
hideCreate
: If set to true
, the field will be hidden from the create operation, so the field cannot be 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.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.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
The npm package @panter/crud receives a total of 17 weekly downloads. As such, @panter/crud popularity was classified as not popular.
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 0 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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.